How to stop my object from going through another object

Hi

I have an object that moves towards another object, a probe that moves towards a cube, I used a script for movement my problem is that my probe doesn’t stop when it reaches the cube but it keep going through it and I want it to stop. I’ve tried box collider, mesh collider rigid-bodies on both objects with no luck so far, my probe is inside a gameObject.

Any tips or guidance on how to stop my object going through the cube is really appreciated.

I will suggest you to use add force on rigid body but anyway, If you want to use transform.position that is

if(dist > move){ transform.position += dir.normalized * move; }

then you can use IstriggerEnter() function to detect your collision and when collision occurs you just need to stop your code

if(dist > move){ transform.position += dir.normalized * move; } to execute.

you can put a condition in your if()

if(dist > move && collisionOccured== false){ transform.position += dir.normalized * move; }

and In onTriggerEnter() write
OnTriggerEnter(){ collisionOccured = true; }
. For triggerEnter your both bodies must have collider on them and atleast one of them should be a rigid body.

You seem to be directly modifying its transform.position, which will not take any physics into consideration. (transform.position += //your code)

Try adding a rigidbody to the object that you are trying to move and use Rigidbody.AddForce.