The problem was solved by myself
How to make an object stop when the distance between it and another object reaches 0 ?
Hello Guys! (in particular @xXJuanXx )
I have another problem which is a little bit complicated. I looked for my problem in the question section already but I could not find any question which describes my problem perfectly.
I want to calculate the distance between to objects and I want them to stop if the distance between them (or other objects) reaches 0. I can try to implement this by using a collision function but I am not very practiced in Unity. So I tried to figure it out in another way but it did not work. The function did not want to show me distance between the objects or something else.
My distance function without making the object stop:
void Distance()
{
if (other)
{
float dist = Vector3.Distance(other.position, transform.position);
print("Distance to other: " + dist);
}
}
Answer by Falden · Nov 17, 2016 at 01:14 PM
Try something like: https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html if you wanna learn how to handle collisions.
If you simply want to check if they are on the same position then:
if(Mathf.Abs(Vector3.Distance(other.position, transform.position)) <=0){
Debug.Log("They are on the same position!");
}
should suffice
I implement your suggestions but the distance doesn't show up :/
Follow this Question
Related Questions
Collision issue, Plz help 1 Answer
How i can fix a player controller bug? 0 Answers
Lose Health when GameObject enters collider? (OnTriggerEnter) 2 Answers
What is ContactPoint.point? 0 Answers
Collision With Text 0 Answers