I was wondering if you could do a tutorial on how to apply make a 3D Model Jump, and apply Gravity, i'm still trying to figure out how to do it, i can raise a model up on the Y Axis, but i'm a little bit puzzled as to how to apply Gravity to a 3D Game, and also what the simplest way to apply Collision Detection so that a Model will land on a surface, i am aware that collision between a Heightmap and another model are different from 2 models colliding (I've been trying to code from a few books i have, best example i've gotten closest to was using in 3D Graphics with XNA Games Studio 4.0 by Sean James, though i remain a little unsure how to approach the code.)
i would be ever so grateful for any advice or suggestions
This is something a lot of people wonder about, so it would be a good thing to write a tutorial about. It's actually the kind of thing that's pretty high on my priority list.
I probably can't do this justice right now, in the time I have, but I wanted to throw out a couple of quick ideas on gravity and collision detection, perhaps to keep you from getting completely stuck in a rut.
Gravity is usually thought of as a downward acceleration. An acceleration is a change in velocity over time. A velocity is a change in position over time.
So your character will need to have a position in 3D (Vector3, perhaps?) but also a velocity. You may want to keep track of velocity in all three directions, but if your player's speed forward/back and side-to-side is essentially just pulled from the position of the Xbox's thumbstick or something, you could probably get away with just tracking the player's velocity up and down. So the character might have a "verticalSpeed" variable or something.
When the player is walking around, their falling speed would be 0. When they jump, you'd set it to some value, based on how strong they are and how high you want them to jump. Let's say 5, but that's really just an arbitrary number.
Now, each update, you'd change their position in the up/down axis (I usually use the y-axis to represent up and down, but some people like the z-axis for that instead. Either one works.)
So in the Update method for your character, it would be something like this:
position += new Vector3(0, verticalSpeed, 0) * gameTime.ElapsedGameTime.TotalSeconds;
I don't remember if my game time code is perfectly correct, but I have tutorials on my site that go into timing a little more. I can help you locate them if you need them and can't find them.
But with just that code, it will be like there's no gravity, and the player will keep flying higher and higher up. Cool, but not what you're looking for.
So you have another variable, which could be a constant somewhere, that defines how strong gravity is. (Interestingly, when you get it all working, you'll be able to adjust this value and pretend you're playing on the Moon or Mars. Or Jupiter.)
Let's say you've made a class called Constants, which has a public static readonly float Gravity = -2.0f; defined in it.
You'll want to change your player's verticalSpeed by this amount every update as well:
verticalSpeed += Constants.Gravity * gameTime.ElapsedGameTime.TotalSeconds;
So now your vertical speed is changing over time. Eventually, the speed will change directions, and the player will reach the top of their jump and begin falling.
When they reach the ground again, you'd set their verticalSpeed back to 0, and quit changing it (or they'll keep falling).
With a flat ground, this might work something like this:
if(position.Y <= 0) // More complicated with a terrain, or with other objects in the game that you can jump on. { playerIsFalling = false; position.Y = 0; verticalSpeed = 0; } if(playerIsFalling) { verticalSpeed += Constants.Gravity * gameTime.ElapsedGameTime.TotalSeconds; position += new Vector3(0, verticalSpeed, 0) * gameTime.ElapsedGameTime.TotalSeconds; }
I sincerely apologize, as that's all I have time for right now. But I'm hoping it's a start, and gives you some ideas to try out.