- Home /
Question by
Broseph1010 · Jul 18, 2018 at 03:40 PM ·
c#vector3quaternionforceconstant force
How can I set a ConstantForce's force to move the object towards another object?
I need to know how I could set a ConstantForce's force so it can move an object towards another. Any help will be appreciated. It doesn't even have to be code, even just a formula works. Sorry I do not have any code to share, this is the basis of my code, so I haven't started yet. Thanks!
Comment
Answer by David_Simoniants · Jul 18, 2018 at 04:48 PM
//obj and target are the transforms of the moving object and target object
var constForce = obj.GetComponent<ConstantForce>();
constForce.force = (target.position - obj.position).normalized * force;
Your answer
![](https://koobas.hobune.stream/wayback/20220612171013im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
calculating looking angle between 2 transforms 0 Answers
Pose.ctor - create pose from vector3 and quaternion 1 Answer
Slerp look at direction not working... 3 Answers
Multiple Cars not working 1 Answer