- Home /
Does AddForce in rigidbody2D work in m/s?
Hi,
I am a bit confused about physic units in unity.
I have read that unity default distance unit is in meters and speed is in m/s. I have a little test map made of 1x1x1 cubes and when I launch a projectile say at a velocity of (0,20) it doesn't travel at 20cubes/s. It travels much slower. Am I missing something?
Thanks in advance.
Answer by Dblfstr · Mar 13, 2014 at 03:35 PM
Force and velocity are two different things. If you add force, you are adding 20 newtons (depending on the mass of your object). And, it depends on how you are applying. Are you applying once, are you applying every update? What is the force mode; impulse, force? But yes,
velocity is in m/s,
acceleration is m/s^2
and
force is newtons, 1kg(m/s^2).
I was so sick of trying things that I messed the units. Thanks for clarifying. I knew I needed a pal to check from outside. I'm just applying it once. It is just an impulse. On the other hand there's something wrong here anyway. I have work out some maths to make a projectile fly from a point to another starting at an angle and intial speed. I have checked everything is ok drawing a curve to see results and everything is ok. Anyway, the same problem arises with the force applied to my projectil. It does not fly a meter. Here the colde:
float angle, initialSpeed;
//This function returns a valid angle and initialspeed from this T to playerT
_GetValidAngleToTarget(_playerT,out angle, out initialSpeed);
GameObject go = (GameObject)GameObject.Instantiate (bulletPrefab,t.position,Quaternion.identity);
float x = $$anonymous$$athf.Cos (angle);
float y = $$anonymous$$athf.Sin(angle);
float force = initialSpeed * go.rigidbody2D.mass;
go.rigidbody2D.AddForce(new Vector2(x,y)*force);
It is really weird. Gravity is set in both simulations at same acceleration -9.8 m/s^2.
Thanks in advance.
To let everybody know I fixed my issue applying an impulse this way:
http://forum.unity3d.com/threads/213397-Rigidbody2D-Force$$anonymous$$ode-Impulse
It seems applyForce must be applied every frame to let it work.
Right, the rigidbody2D sucks in this way. it will slowly apply a little force over each update. The Impulse Force$$anonymous$$ode (available to RigidBody) is great because you can apply all the force at once (like it would really work). The rigidbody2D force acts more like acceleration than force. Glad you got it worked out though.