# topdown physics.

This topic is 2943 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 frictionif(_Force.lengthSquared() > _ForceStaticFriction * _ForceStaticFriction){   _Force = _Force.sub(_Force.normalize().mul(_ForceStaticFriction));   /// Means...   /// _Force = _Force - _Force_ForceStaticFriction;}_body.applyForce(_Force,_body.getWorldCenter());

##### 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 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)
$v=v_0+a*dt$
2.I move around elements assuming v=0
$a=\frac{0-v_0}{dt}$
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.$F=a*m$

If i joint these two equations together i get this.
4.$F=\frac{0-v_0}{dt}*m$
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.
$F_s=g*m*k_s$
Kinetic friction. kk is kinetic friction coef
$F_k=g*m*k_k$
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)
$F_friction=F-F_k$
else
$F_friction=F$

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

//this are all equations together.
$v=v_0+a*dt$
$a=\frac{0-v_0}{dt}$

$F=a*m$

$F=\frac{0-v_0}{dt}*m$

$F_s=g*m*k_s$
$F_k=g*m*k_k$

if(F>F_s)
$F_friction=F-F_k$
else
$F_friction=F$

body.setForce(F_friction)

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 13
• 92
• 11
• ### Forum Statistics

• Total Topics
632972
• Total Posts
3009626
• ### Who's Online (See full list)

There are no registered users currently online

×