• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
zqf

Calculating the force to jump an exact distance

6 posts in this topic

Hello there.
This question is about a platform game in box2D but I assume that it would be applicable to any platform game.

At the moment my character jumps by setting his vertical velocity, but I'm at a point where I want to tweak the gravity of the game but not affect the actual distance the player will jump, so I can adjust the feel of the gravity without constantly have to alter the player jump strength.

Gravity force vector in box2D is currently +22 on y.
I want the player body to be pushed upward exactly 3 metres.
The player can double jump, and I want this to happen regardless of what the current velocity of the player is. If the player is falling very quickly, hitting jump will cause them to stop and pop up 3 metres.

Thanks
0

Share this post


Link to post
Share on other sites

Can you code it in such a way that the gravity does not affect the player when jumping?

As far as I know in Box2D its not possible to define an object affected by all physics except gravity. It's all or none.

0

Share this post


Link to post
Share on other sites

Think of it in reverse.  What is the velocity of an object that has fallen 3 meters in a given gravity?  Manipulating the equations for a falling body, v = g * sqrt(2d/g) where d is your 3 meters (or however high you want to jump) and g is your gravity constant.  Once you have that velocity, that is the upward velocity your character needs to start at to hit an apex of 3 meters.

1

Share this post


Link to post
Share on other sites

I guess what you need is to know which linear velocity to apply at the jump so that it reaches X meters high given a gravity, isn't it?

 

You can use basic newtonian physics / SUVAT equations of motion (http://en.wikipedia.org/wiki/Equations_of_motion):

 

  S = VT + 0.5AT^2

 

  S is the distance traveled at time t (meters)

  V is the starting linear velocity (meters / second)

  A is acceleration (meters / second ^2)

  T is time (seconds)

 

In your case S is the jumping height and A is the Box2D gravity (as long as it's also in meters/second^2, it really should) and both may take different but known values. Therefore there are 2 unknowns, V and T. With just one equation it can't can't be solved: Sounds logic, the object can be at a distance S with infinte combinations of V and T. But the combination wee need is the one in which the object has velocity 0 when it reaches S meters (just the instant before it starts falling), so we can use one more formula:

 

  V2 = V + AT

 

  V2 is the final velocity (meters / second)

  The others are the same as before

 

In your case we have

  0 = V + AT

  -AT = V

  T = -V / A

 

Which can be substituted in the first equation:

  S = VT + 0.5AT^2

  S = V(-V / A) + 0.5A(-V / A)^2

  S = -V^2 / A + 0.5 * V^2 / A

  A*S = -V^2 + 0.5V^2

  A*S = -0.5 * V^2

  V = sqrt(A*S/-0.5)

 

When a jump takes place just calculate V using the appropiate S (desired jump height, always positive) and A (gravity, -22 or whatever but always negative) and apply it to the Box2D body. It won't matter if the object was already moving or not.

 

I hope this helps,

Lionel

 

PD: I think the maths are OK but please check them just in case.

 

PD2: Notice that even though the object will jump up up to S meters it will take more or less time depending on the gravity: slow jumps in low G and quick jumps in high G. This can't be avoided unless you fully control yourself the object's position & motion.

 

PD2: Notice this equation will work only if A (gravity) stays constant during the whole jump... I mean, If you are planning to change gravity quite often and it may happen at some point DURING the jump... then this won't work. I guess it will just need some more maths (but not too much).

0

Share this post


Link to post
Share on other sites

Think of it in reverse.  What is the velocity of an object that has fallen 3 meters in a given gravity?  Manipulating the equations for a falling body, v = g * sqrt(2d/g) where d is your 3 meters (or however high you want to jump) and g is your gravity constant.  Once you have that velocity, that is the upward velocity your character needs to start at to hit an apex of 3 meters.

Good thinking. Could you show how you got there? Which equations you used?

0

Share this post


Link to post
Share on other sites

Think of it in reverse.  What is the velocity of an object that has fallen 3 meters in a given gravity?  Manipulating the equations for a falling body, v = g * sqrt(2d/g) where d is your 3 meters (or however high you want to jump) and g is your gravity constant.  Once you have that velocity, that is the upward velocity your character needs to start at to hit an apex of 3 meters.

Good thinking. Could you show how you got there? Which equations you used?

the same ones you did, just different constants (acceleration A = g, S=d distance traveled in time t):

 

s(t)=v*t+(g*t^2)/2 (with s(t0)=d, at some arbitrary time t0, initial velocity v=0) => d=(g*t0^2)/2

=> sqrt(2d/g) = t0 (I)

for any time t:

v(t)=g*t (II)

is true, by calculating total derivative of s: ds/dt = v (change of distance s per time t is velocity v by definition)

this is especially true for time t0:

(I) substituted into (II): v0 = v(t0) = g*sqrt(2d/g) = sqrt(2dg)

q.e.d.

 

so whats actually calculated here is the speed the object has after falling d units (starting at s=0, going to s=d, with initial velocity 0, trying to find end velocity v0).

since ideal newton physics are symmetric in time its the same the other way around.

Edited by Tasche
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0