Unity pull objects with rope

807 Views Asked by At

How can I create a winch system like in Mudrunner, to pull objects? Or to pull other vehicle or rigidbody object with rope? I saw in mudrunner winch system and I am very interested on how to make it in unity. You can pull yourself to objects or to pull vehicles that are stuck example

1

There are 1 best solutions below

0
Toll Gnoll On BEST ANSWER

If I understand correctly, when you pull an object, you want the direction of it to remain the same but the distance of it to the stationary object to decrease.

In the case of GameObjects "target" and "pivot" where "target" needs to be pulled towards "pivot", the direction "target" needs to move can be found using this:

Vector3 pullDirection = (pivot.transform.position - target.transform.position).normalized

Moving the target in this direction would pull it towards the pivot. You can use any of the following methods to move it, where rb is the target's rigidbody:

rb.AddForce(pullDirection * forceStrength)
rb.MovePosition(target.transform.position + (pullDirection * pullSpeed))

Set pullDirection or pullSpeed to whatever you think will work best for your game.