Align to floor
Blitz3D Forums/Blitz3D Programming/Align to floor
| ||
Hello again everyone :) I'm creating a game where the player is moved by the user clicking on the terrain and the player moves towards it. but when the terrain goes downhill the player floats through the sky. How can i always keep him on the floor? I did just think about doing: MoveEntity (player, 0, -0.1, 0) But this makes the character slide down hills, or if the player falls off from a high he just slowly floats down. any ideas? Thanks as always :) |
| ||
If you still want to retain some form of gravity then use translateentity player, 0, -whatever_number_feels_right, 0 This ensures that gravity will always point down regardless of player orientation. I'd also make sure that you have the collisions set for non-slide. Option 3 I think. If you want to ignore gravity then why not simply position the player at the terrain height based in it's x and z coords. I think the command is terrainy() to get this height. Stevie |
| ||
Here's how i like to do it :)If PlayerNotOnFloor() then VerticalVelocity = VerticalVelocity -0.01 If PlayerCollidedWithFloor() then VerticalVelocity = 0 TranslateEntity( Player x, VerticalVelocity, x ) |
| ||
One small change:EntityType groundentity, 1 EntityType playerentity, 2 Collisions 2, 1, 2, 3 If PlayerCollidedWithFloor() VerticalVelocity = VerticalVelocity -0.01 Else VerticalVelocity = -0.01 EndIf TranslateEntity(playerentity, 0, VerticalVelocity, 0) Function PlayerCollidedWithFloor() If EntityCollided(playerentity, 1) Then Return True End FunctionYou should always be applying gravity. Don't set it to zero. |
| ||
"You should always be applying gravity. Don't set it to zero." Could you explain that one to me WolRon? my understanding is, if the entity is colliding with the floor, then upward force would be exactly equal to downward force... the result being 0? I'm not diagreeing, just trying to understand your way :) |
| ||
um but it wouldnt set gravity to zero would it, it would just mean the moment result would be zero. |
| ||
My way would cause the player to touch the floor (due to gravity) every loop of the program. Your way would cause the player to touch the floor every other loop of the program. Run it in debug and step through and you'll see. |
| ||
*enlightened* ahhh yes, i never thought of that! Thanks WolRon |