Pulling in another object using AddForce()

Hi.

I haven’t spent much time with physics in Unity, thus I can’t solve a basic problem. I’ve checked this forum and Uncle Google for a solution. Sadly, without success.

What I want to do is OBJECT1 pulls in OBJECT2, and both of them have rigidbody attached. While OBJECT1 is pulling OBJECT2 both of them are under Unity’s physical laws.
What I have now is:

Vector3 diff = object1Transform.position - object2Transform.position;
object2Transform.position += diff.normalized * 0.2f;

This is working, but of course it causes a conflict with physics (for example when OBJECT2 is changing position, its velocity doesn’t). Therefore I would like to use AddForce(), but I can’t get proper direction in which that object should be forced (and should be forced in direction of OBJECT1 position). I believe you can help me.

By the way, if you have any good resources for understanding physics in Unity, let me know please.

I appreciate any help.

Okay, I solved the problem.

What I did is I used AddForceAtPosition(dff.normalized, object2Transform.position, force), and turned off gravity of object2 while pulling. When pulling is finished object2 gravity is turned on again. Works perfectly!

But still, if you have any good resources for learning, post it please. :wink: