OnCollisionEnter Trigger

I am creating an OnCollisionEnter trigger, but having syntax trouble.

if I want OnCollisionEnter to stop transform.translate, how do I write that?

OnCollisionEnter;
transform.translate(0,0,0)

I read the documentation, which wrote OnCollisionEnter as a void, however I get an error regarding the ‘void’ part.

Hi there @TheRedGuy90

It’s pretty plain to me here that you’re probably misunderstanding what OnCollisionEnter is. OnCollisionEnter is a method and thus cannot be used as a statement. To use the OnCollisionEnter method you must define the method within your class and then perform the statements within it, for example:

void OnCollisionEnter (Collision other)
{
      transform.Translate(0,0,0);
}

That will now check for a collision and then stop the player’s movement when they collide with an object. If this does indeed sound like the problem you were having I would highly recommend you pick up a beginner’s book on C# before attempting to go any further otherwise it’s going to be an uphill struggle.

I hope this helps!