Munger wrote:As for your movement code, I'm glad to tell you your collision/response code must be working. Not letting the camera go under the terrain is step #1. The next step is applying gravity. You say that when you let go of the key it fixes itself. Does that happen instantly, or does it have a smooth drop? If it's instantly, you're probably just snapping the character to the ground when there's no input. If you're going to do this properly, you'll need a little bit of physics...
I'm using gravity with the collisionAnimator like it does in the demos. I think the problem is that every "frame" I'm only telling it to move forward from its previous position so the y-axis isn't getting updated. When I'm not making it move forward then it falls down to the ground like normal. (You can see this near the end of that video I posted a few posts back.)
Your character needs a position and a velocity. You have a tick every frame that adds a bit of the velocity to the position. This sounds like what you have already. When you want to move the character, you have to add acceleration to the velocity (and then the velocity modifies the position in that tick). So how does this help your motion? Gravity is a form of acceleration (a force acting on your object). Every tick, add gravity to your velocity as well as the forces from player input and collisions.
When you collide, you've got some thinking to do and decisions to make. Realistically, your character should be 'reflected' off the surface it collides with. To make things easier, you could just make it that characters lose all vertical velocity when they touch the ground and lose part of their horizontal velocity as a kind of friction. That'll keep the mathematics simple and look good-enough to get you started.
I was thinking something along the lines of getting the distance between the character and the ground, and if it's not close enough to the ground then move the character down a bit.
Once you start getting more complicated than that, you might want to consider using a physics engine (like ODE or PhysX). That obviously has it's own share of hassles and sometimes for a game you'll find yourself turning things off to make it feel 'right' (like rotational velocity so your character stays upright).
Only problem is that JNewton is the only decent jirr-friendly physics engine out there at the moment (that I've come across at least) and it generally looks like a lot more of a pain than I had hoped for.
I'll go add the thing with the downwards velocity now. Thanks again!