trajectory for an entity

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
weby
Posts: 6
Joined: Tue Jan 05, 2010 8:30 pm

trajectory for an entity

Post 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.
Attachments
Trajectory.png
Trajectory.png (385.65 KiB) Viewed 4882 times
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: trajectory for an entity

Post 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.
weby
Posts: 6
Joined: Tue Jan 05, 2010 8:30 pm

Re: trajectory for an entity

Post by weby »

Thanks ! :D I will try this and I post the answer if it work. :wink:
weby
Posts: 6
Joined: Tue Jan 05, 2010 8:30 pm

Re: trajectory for an entity

Post 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?
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Re: trajectory for an entity

Post 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 :)
weby
Posts: 6
Joined: Tue Jan 05, 2010 8:30 pm

Re: trajectory for an entity

Post by weby »

thank you it works!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: trajectory for an entity

Post 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.
Post Reply