# 3d Enviroment

This topic is 3625 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Could anyone explain how players move around in 3d enviroments with more than one level? Currently i just have my players walking around an outdoor enviroment, where their yPos are calculated from the terrain heightmap. But lets say you have an outdoor scene, which uses a heightmap, and then on that terrain you have a building with multiple stories. How do you work out the players y pos when they move from being on the terrain to being in the building. Lets say there is a set of stairs to move between floors, how do you intereact with the stair mesh to move the player up the stairs? and also, once they are up the stairs, without a heightmap, how do you work out whether there is actually another floor, at the end of those stairs to walk onto? I gather that its all collision detection, but how does it work? I have an idea in my head, that you just scan the objects around you and calculate where you can step onto them or not. But i have no idea on how to start implementing this. I mean for calculating whether or not the play can step onto a box or not is simple enough, just compare player heaight to box height. But when you have have a set of stairs, this task becomes a lot more difficult. What sort of material should i be looking at for this kind of thing?

##### Share on other sites
Better not to reinvent the wheel, so I would suggest you look into using an existing physics engine.

##### Share on other sites
Yes, it's fundamentally a collision detection/physics problem. in a 3D environment you move the player by sliding around a capsule and collsion detecting it against the world geometry. Player pushes forward -> attempt to move the capsule an appropriate amount based on time passed -> if it collides, move it back to the furthest non-colliding position along the vector of movement.

I strongly agree with swift. Look into using PhysX or some other freely available physics SDK. You'll need a good understanding of kinematic newtonian physics and linear algebra for it to make sense (but you'll need a great deal more understanding to write it yourself).

Otherwise the book Real-Time Collision Detection is pretty badass. I'd also recommend picking up a copy off amazon or getting one from your local library.

-me

##### Share on other sites
Back when I didn't use a physics engine I did it this way, keep in mind that this was for a fps with a quake-like engine but I guess the principle is the same. I represented the player as a aabb and the world could be considered as a polygon soup. The techniques shouldn't really matter as long as we can trace a path from two points and get collision info for that potential collision, such as normal and the point of collision.

Anyway, first we should add gravity. Every frame move the character up by V, and decrease V. Set V to zero when you hit something. V is your vertical movement. Setting it to something positive when your on the ground makes your character jump.

Time for horizontal movement.. Get your In and Right vectors, set their Y values to zero and multiply them with forward/backward and right/left floats and sum the resulting vectors to get your movement direction. Normalize and multiply with movement/frame to get your wanted movement.
If you can go in a straight line that is good, however there are two things to think about. The first is the StepUp part, and the second is sliding. Sliding is easy as it is just a matter of getting the collision surface normal and getting a movement vector along that collisionplane, so we'll focus on the StepUp. What you really need to do is to actually step up. Move uppwards some small distance(the height of stuff you want to step over) until you get a collision. Then move forward, and finally down the same distance you move up.

That's the basic technique, you could add more features as you want, for example saving the horizontal momentum, doing continous StepUp's when colliding during forward movement and sliding under gravity, probably only when the angle is greater than some constant. It's basically just a matter of establishing how your environment looks like based on testing for collisions and testing it allot. That's how I did it at least :)

Using a physics engine is fine if you, for example, aren't caring how you step over stuff but just that you are stepping over them. If you need to play a special animation depending like climbing up something or vaulting over something else you just can't rely on a capsule :)

Hope that helps.

1. 1
2. 2
3. 3
Rutin
20
4. 4
khawk
14
5. 5

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633655
• Total Posts
3013186
×