- Home /
Question about movement!!!
I am very, and I MEAN VERY new to Unity and C#! I want to stop movement when it hits an obstacle, but there is a problem with this script. What is it? Please help!
using UnityEngine;
public class DEMOCollisionEnter : MonoBehaviour {
void OnCollisionEnter(UnityEngine.Collision collisionInfo)
{
if (collisionInfo.gameObject.tag == "Obstacle")
{
movement.enabled = false;
Debug.Log("We hit an obstacle!");
}
}
}
What is movement
in this context? Can you tell us the type?
@$$anonymous$$imimaru Oh, sorry. That is kinda the issue. It is saying movement is not an actual word in Unity. I was trying to look up tutorials for beginners and the most beginner one was made by Brackeys. It is really old though and it doesn't really work properly since they updated Visual Studio. When I typed in movement.enable = false; Brackeys said that it would stop movement if it collided into a tagged obstacle. So I am assu$$anonymous$$g it is there to make movement false. Then the error popped up saying movement is not a word. Hopefully that made sense because I suck at explaining things.
Some more context would help. What kind of object are you trying to move and stop? Can you show the scripts on that object? Is it a Rigidbody or custom-built movement solution?
Answer by abi-kr01 · Nov 16, 2018 at 09:28 AM
I would suggest you to use triggers instead of collider. just tick is trigger "true" . One thing you have to check is one of the game object should have rigid-body preferably the object that is moving .
private void OnTriggerEnter(Collider otherObject)
{
if (otherObject.gameObject.tag == "Obstacle")
{
movement.enabled = false;
Debug.Log("We hit an obstacle!");
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612182221im_/https://answers.unity.com/themes/thub/images/avi.jpg)