- Home /
How could I use AddForce() towards another Object without using transform.forward
I basically want a comet to shoot towards a planet but I want the comet also to rotate. I've looked around and lots of people are saying to use transform.LookAt and then rigidbody.AddForce (transform.forward)
How could I achieve this effect without using LookAt
Answer by tanoshimi · Dec 16, 2014 at 07:17 PM
rigidbody.AddForce(target.position - transform.position);
@tanoshimi Thanks works. How would you change the power of the AddForce?
Yep.
rigidbody.AddForce((target.position - transform.position) * multiplicationFactor);
Without normalising the Vector it has magnitude as well as direction, this will mean the power of the force will change according to the distance between the two objects. Not just the power you give it.
The rest of the script is caching the transforms of the necessary objects. Which is faster performance wise than not doing. Something I would strongly advise you to get into the habit of doing early on.
...and setting up a force var, and a target var(for easy selection for use in this example)...