Sign in to follow this  
PJani

topdown physics.

Recommended Posts

Hey, i need to implement top down physics in jBox2D and i need some tips about linear and angular friction.

Recently i was using this equations, which were producing non natural effects.


_needed_velocity = 0;
_needed_velocity = _current_velocity + _acceleration * time_delta;
0 = _current_velocity + _acceleration * time_delta;
//after
(0 - _current_velocity) / time_delta = _acceleration;
_acceleration = (- _current_velocity) / time_delta; //which were producing large large number but it worked.



//this is just an example of my concept non natural concept.

_acceleration = (- _current_velocity) / time_delta;
_Force = _acceleration * _body_mass;

_ForceKineticFriction = 0.525 * _body_mass * 9.81; // kinetic friction
_ForceStaticFriction = 0.900 * _body_mass * 9.81; // static friction

if(_Force.lengthSquared() > _ForceStaticFriction * _ForceStaticFriction)
{
_Force = _Force.sub(_Force.normalize().mul(_ForceStaticFriction));
/// Means...
/// _Force = _Force - _Force_ForceStaticFriction;
}

_body.applyForce(_Force,_body.getWorldCenter());





Share this post


Link to post
Share on other sites
PJani,

Please give us a bit more information. Can you give us an example of the type of effect you are looking to produce? You don't have to describe your game in detail, if you don't want to. I'm just looking for a concrete example that we could use for judging the code. It will help understand what you mean by "non natural effects," for example.

Share this post


Link to post
Share on other sites
I have totally missed that part. :)

Ok, lets start.
I have jBox2D physics engine i would like to use it for topdown. I implemented my own prestep callback which is called before world.step(); in which will update topdown bodies. This is no problem.

In first attempt to add "realistic" topdown friction.

1.If i want to stop body to move the end velocity must be 0(v=0). and v, v0, a are vectors. v0 is current speed, dt is time step. a is body acceleration(which i am looking for)

2.I move around elements assuming v=0

This gives me accleration which is needed to stop body from moving in timestep t.

Force is: (a is acceleration, m is mass of the body)
3.

If i joint these two equations together i get this.
4.
This is force which stops body from moving in current timestep. Which actually is very unnatural.

5. I took friction force in consideration which would make body realistic, but it dont.

6. Friction equations. g is gravity constant.
Static friction. ks is static friction coef.

Kinetic friction. kk is kinetic friction coef

Assume the F_k and F_s are all ready aligned with F;(F_k=(F/|F|*F_k)).

7. I check if F is greater than F_s and if is greater than static friction then i substract F_k from F. else if use F as force.
if(F>F_s)

else


at the end i apply this F_friction to body at the center of mass.

//this are all equations together.










if(F>F_s)

else


body.setForce(F_friction)

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