Search Unity

1 object follows another, but if it gets stuck it should stop the other object. How?

Discussion in 'Physics' started by AlexTemina, Aug 10, 2016.

  1. AlexTemina

    AlexTemina

    Joined:
    Feb 19, 2014
    Posts:
    44
    Ok, something is bugging me a lot.

    I have an object that controls another object. Whenever object1 moves, object2 follows it. So object1 position is always object2 position + offset.

    Object2 has a rigidbody, so it can collide with things. When that happens, object2 stops and object1 should now to stop, as well. Think about a flying object that goes up and a platform underneath. The platform can get stuck so the flying object should know this and stop.

    I would normally check if the offset got bigger than it should, and then I tell object1 to stop, or I tell object1 to go back and keep the position. I do this in FixedUpdate.

    The problem is that object1 tries to move again, object2 is still stuck so it doesn't move, and again offset is bad and again it goes back. This makes object1 bounce continuously. I really don't know how to avoid this, if there is a way to "test" physics before actually moving the object.

    The other solution is to tell object1 to stop completely, but how do I know when object1 can move again? I tried many things with collisions, but everything is unsatisfactory and erratic.

    Thanks for your help