bouncing/jumping object - how?
hello!
in my 2d game i would like to create my playerbob can jump via pressing any key... my only problem is that i dont know a algorithm for let the player jump 40 pixels high or higher in a smooth circle using velosity and so on...
i hop my bad english can explain my probl.
thanks for any help
elmo
well, at it's most basic, here's how you would move a player via velocity every frame:
===============================
//somewhere at a global level
Vec3D Velocity; //x/y/z vector
Xform3D xform; //player's 4x4 transform matrix
//inside your game loop
if (!(Velocity <= 0) && !OnGroundPlane)
Velocity -= Gravity;
if (MoveForward)
Velocity += GetForward(xform) * MoveScale;
if (MoveBackward)
Velocity += -GetForward(xform) * MoveScale;
if (MoveLeft)
Velocity += GetLeft(xform) * MoveScale;
if (MoveRight)
Velocity += -GetLeft(xform) * MoveScale;
if (Jump && !OnGroundPlane) {
Velocity += GetUp(xform) * JumpForce;
OnGroundPlane = false; //prevent multiple jumps
}
if (OnGroundPlane)
Velocity -= Friction;
ClampVelocity(Velocity, 10.0f);
if (Velocity < 0.01f)
Velocity = 0;
===============================
that's fairly simple and should get you going.
Edited by - revolver on 3/20/00 9:50:36 AM
===============================
//somewhere at a global level
Vec3D Velocity; //x/y/z vector
Xform3D xform; //player's 4x4 transform matrix
//inside your game loop
if (!(Velocity <= 0) && !OnGroundPlane)
Velocity -= Gravity;
if (MoveForward)
Velocity += GetForward(xform) * MoveScale;
if (MoveBackward)
Velocity += -GetForward(xform) * MoveScale;
if (MoveLeft)
Velocity += GetLeft(xform) * MoveScale;
if (MoveRight)
Velocity += -GetLeft(xform) * MoveScale;
if (Jump && !OnGroundPlane) {
Velocity += GetUp(xform) * JumpForce;
OnGroundPlane = false; //prevent multiple jumps
}
if (OnGroundPlane)
Velocity -= Friction;
ClampVelocity(Velocity, 10.0f);
if (Velocity < 0.01f)
Velocity = 0;
===============================
that's fairly simple and should get you going.
Edited by - revolver on 3/20/00 9:50:36 AM
Creativity is a bloody nuisance and an evil curse that will see to it that you die from stress and alcohol abuse at a very early age, that you piss off all your friends, break appointments, show up late, and have this strange bohemian urge (you know that decadent laid-back pimp-style way of life). The truly creative people I know all live lousy lives, never have time to see you, don't take care of themselves properly, have weird tastes in women and behave badly. They don't wash and they eat disgusting stuff, they are mentally unstable and are absolutely brilliant. (k10k)
sorry but i dont understand nothing of this...perhaps today is stupid day, or my teethdoc has deleted my brain yesterday
normaly my ypos of my player are defined as:
ypos=ypos-speed; for jumping and ypos=ypos+speed for falling down...
but my probl. is the var speed - i must have linear values, so speed is first 6 pixel than 4 pixel than 3, than 2, than 1 and so on... but in my game i have different jumphights from 40 to 100 pixels high (its a plattform game) so how to create a linear value list for speed?
thanks for all
elmo
normaly my ypos of my player are defined as:
ypos=ypos-speed; for jumping and ypos=ypos+speed for falling down...
but my probl. is the var speed - i must have linear values, so speed is first 6 pixel than 4 pixel than 3, than 2, than 1 and so on... but in my game i have different jumphights from 40 to 100 pixels high (its a plattform game) so how to create a linear value list for speed?
thanks for all
elmo
hm.. your problem is not really clearly defined here. I could take the complex viewpoint, which means that you want to have a character be able to jump to exactly 40 or 100 pixels in a specified time frame, which would require some physics to get right. If that is the case I will reply again.
But, the simple case would be just that you want the character to jump and fall in a parabolic fashion, which can be approximated very easily. Just have 3 variables,
y position, y speed and y acceleration (make these all floats). Here are the steps you would need to go through to make a person jump:
Step 1:
ypos = 0; // at ground
yspd = 0.1; // 0.1 pixels per frame
yaccel = -0.001; // acceleration in a downwards direction
Step 2: (do this every frame)
ypos += yspd;
yspd += yaccel;
and there you have it, gravity modeled realistically enough for a platform game.
But, the simple case would be just that you want the character to jump and fall in a parabolic fashion, which can be approximated very easily. Just have 3 variables,
y position, y speed and y acceleration (make these all floats). Here are the steps you would need to go through to make a person jump:
Step 1:
ypos = 0; // at ground
yspd = 0.1; // 0.1 pixels per frame
yaccel = -0.001; // acceleration in a downwards direction
Step 2: (do this every frame)
ypos += yspd;
yspd += yaccel;
and there you have it, gravity modeled realistically enough for a platform game.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement