Page 1 of 1

trajectory for an entity

Posted: Sat Jun 12, 2010 4:04 pm
by weby
Hi,

In my game I have some enemies who have to jump to find and hit the player. So my enemies have to go to their end point and follow a parabolic trajectory.

You can look at the attachement to understand :-).

How can I do precise parabolic trajectory with Bepu?

Tank you for your help and your great API.

Re: trajectory for an entity

Posted: Sat Jun 12, 2010 7:33 pm
by Norbo
There's a couple of things you could do. First, parabolic trajectories like this come naturally from gravity. If you compute a correct initial velocity and apply gravity while the object is in the air, it would create the desired jump path.

To figure out the necessary initial velocity to create the parabola, you use kinematic equations. For example, using:
Y - Y0 = V0 * t + 0.5 * g * t^2
where Y is the target height, Y0 is the initial height, V0 is the initial vertical velocity, g is gravity, and t is the time it takes to reach the target height, you can compute V0.
Let's say your initial height is 0, your target is 4, gravity is -10, and target time is 4.
4 - 0 = V0 * 4 + 0.5 * (-10) * 4 ^ 2
4 = 4V0 - 5 * 16
V0 = 21

You'll also need to compute the horizontal component of the velocity by dividing the horizontal distance by time (or choose an arbitrary horizontal velocity and compute time based on it and the distance). Combine the two components and that's the initial velocity.

Another way to do it is to follow a 'path.' This is something that will be explicitly supported in an upcoming version. Basically, you create a parametric curve of some kind, and each frame, you evaluate the curve for the current time. The evaluation will provide a position which you can then try to reach by either setting an appropriate velocity or setting the position. Usually, moving objects with velocity is preferred because that keeps interactions continuous, whereas setting positions is like teleporting the object every frame.

Re: trajectory for an entity

Posted: Sat Jun 12, 2010 8:16 pm
by weby
Thanks ! :D I will try this and I post the answer if it work. :wink:

Re: trajectory for an entity

Posted: Thu Jun 17, 2010 1:28 pm
by weby
Hi !

Thank you my enemies are very inteligents now ! :)

But I have an other probleme :
My game is a race, so it's quick, but when the player fall it's slow (with g = -10)... I thought I can increase gravity but the enemy trajectory began false and if I increase the mass of the player Entity there is no change...

Can you help me again?

Re: trajectory for an entity

Posted: Thu Jun 17, 2010 2:51 pm
by Danthekilla
Hey

try setting

space.simulationSettings.timeStep.timeStepDuration = 1 / 30f;

This makes the engine update twice as much time per frame as the default (the default is 1/60 i think)

you could also try setting

space.simulationSettings.timeStep.useInternalTimeStepping = true;
space.simulationSettings.timeStep.timeScale = 2f;

which tells the engine to use its own internal time step and to work twice as fast. the 2f can be any float.


If none of this works or helps you im sure norbo will later :)

Re: trajectory for an entity

Posted: Thu Jun 17, 2010 3:39 pm
by weby
thank you it works!

Re: trajectory for an entity

Posted: Thu Jun 17, 2010 7:15 pm
by Norbo
If you're curious, the reason changing mass doesn't affect fall speed is that gravity applies an acceleration, not a constant force. Think about the classic bowling ball and feather in a vacuum demonstration; despite the feather being a tiny fraction of the mass, it falls at the same speed when air resistance isn't a factor.

That set of equations should work for any gravity, but ensure that you pass it the updated space's gravity as opposed to a constant like -10.