Player jumping
by Tri · in Torque Game Builder · 09/23/2005 (3:38 pm) · 5 replies
I'm currently a new user to T2D. I followed the tutorial on side-scroller and went pretty well. Able to get the tutorial to work.
Now i started with my own player and stuck on one part. I know how to keybind to move top, right, left, and down..but how can i make my player jump like Mario. does onyone has a link to similar tutorials i'm looking for or can someone advise me on how to create a function that would do this?
I appreciate for reading my post.
Thanks,
Tri
Now i started with my own player and stuck on one part. I know how to keybind to move top, right, left, and down..but how can i make my player jump like Mario. does onyone has a link to similar tutorials i'm looking for or can someone advise me on how to create a function that would do this?
I appreciate for reading my post.
Thanks,
Tri
About the author
#2
09/25/2005 (12:02 pm)
Hrm I think I replyed to this already. Anyway use apply impulse. It is much better then setting velocity because you dont have to unset the y velocity after x time.
#3
If you have gravity set up (with setConstantForce) in your scene, using setLinearVelocityY will work fine.
09/25/2005 (1:06 pm)
SetImpulseForce and setLinearVelocity do close to the same thing. Basically, setLinearVelocity is changing the linear velocity whereas setImpulseForce is adding to it.If you have gravity set up (with setConstantForce) in your scene, using setLinearVelocityY will work fine.
#4
09/26/2005 (12:58 pm)
Mario, like jumping in most 2D games, doesn't follow the laws of physics. Mario moves upwards at a constant velocity for a certain height as long as the player holds down the jump button. After which time, some form of "gravity" takes over, but even that has a maximum velocity that, depending on the Mario game) bears some similarity to Mario's upward velocity. So, the logic is far more complex than simply turning on gravity and applying a force.
#5
I think it *is* that simple, at least in modern 2d scrollers. The upward velocity isn't constant - at least not in any game I've played recently. The jump action sets a negative Y velocity, and gravity force is applied every frame and slowly adds to the player's y velocity until it turns positive -- falling -- and the collision code or whatever physics callbacks are in place should handle colliding with the ground.
One style of platform game lets the player move freely in the X direction while the player is in the air (see Mario, Metroid)
Other games set the X velocity at the moment of the jump depending on if the right or left key is held down at the moment of jumping, and the player can't be moved left or right until they're on the ground. This is closer to reality (see old Castlevania, Ghosts and Goblins).
Tri: Do this somewhere in your player creation code.
1. Apply a constant force (gravity) to the player in the positive Y direction (down)
(you may have to set and unset this force, depending on whether the player is on the ground or not)
2. Set a maximum Y velocity that is appropriate (so the player doesn't fall *too* fast)
3. Bind the jump key to $player.setLinearVelocityY(-jumpSpeed)
4. Bind the jump key off to $player.setLinearVelocityY(0)
(this is so the jump will stop short if the player lets go of the key. This is not reflective of actual physics)
5. Handle collisions, so that if a player hits the "ceiling", the Y velocity is set to 0 (if it was < 0)
The jumping is the easy part. The hard part is handling collisions. :)
Good luck!
09/30/2005 (8:17 pm)
Quote:Mario, like jumping in most 2D games, doesn't follow the laws of physics.Very true, but a 2d game that strictly followed the laws of physics wouldn't be very fun. :)
Quote:So, the logic is far more complex than simply turning on gravity and applying a force.
I think it *is* that simple, at least in modern 2d scrollers. The upward velocity isn't constant - at least not in any game I've played recently. The jump action sets a negative Y velocity, and gravity force is applied every frame and slowly adds to the player's y velocity until it turns positive -- falling -- and the collision code or whatever physics callbacks are in place should handle colliding with the ground.
One style of platform game lets the player move freely in the X direction while the player is in the air (see Mario, Metroid)
Other games set the X velocity at the moment of the jump depending on if the right or left key is held down at the moment of jumping, and the player can't be moved left or right until they're on the ground. This is closer to reality (see old Castlevania, Ghosts and Goblins).
Tri: Do this somewhere in your player creation code.
1. Apply a constant force (gravity) to the player in the positive Y direction (down)
(you may have to set and unset this force, depending on whether the player is on the ground or not)
2. Set a maximum Y velocity that is appropriate (so the player doesn't fall *too* fast)
3. Bind the jump key to $player.setLinearVelocityY(-jumpSpeed)
4. Bind the jump key off to $player.setLinearVelocityY(0)
(this is so the jump will stop short if the player lets go of the key. This is not reflective of actual physics)
5. Handle collisions, so that if a player hits the "ceiling", the Y velocity is set to 0 (if it was < 0)
The jumping is the easy part. The hard part is handling collisions. :)
Good luck!
Associate Peter Robinson
-Peter