- Home /
Question by
nhono99 · May 05, 2018 at 08:43 AM ·
rigidbody2dphysics2dmathrigidbody.addforce
2D AddForce towards direction with CONSTANT FORCE whether the direction is far or near.
I am trying to figure out how to add constant force towards position whether the target position is far or near. Example target vector A (2,10,0) and vector B(20,100,0) the object will have the same velocity by the applied constant force towards A or B.
GetComponent ().AddForce ((pos - transform.position) * power);
How can I achieve it? Other work around or what topic is this in physics(If I must to study it.)?
Comment
Best Answer
Answer by Scribe · May 05, 2018 at 10:05 AM
Look up Vector3.normalize . It will scale a vector so that its length is 1.
(pos - transform.position).normalize * power;
Written on my phone so sorry for any mistakes but you should be able to work it out from that!