while using transform.Translate the gameobject ignores all colliders

Hello, I am trying to just have a simple script that makes a wall move with a hole that the player has to get through, if the player hits the wall it resets the scene. Instead of resetting the scene or just hitting the player with the collider the player just passes entirely through the wall. I’m not entirely sure why it does this. The player and the wall both have colliders.
Here is my script (It’s very simple and im not sure if thats the problem)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class WallMoveForward : MonoBehaviour {
    public float speed = 1f;
    void Update () {
  

        transform.Translate(0, 0, speed * -Time.deltaTime);
    }
}

Physics objects need a Rigidbody and need to be moved with forces.

Translate will just basically teleport through objects and ignore colliders.

Thanks! I changed the code around to just add a force to the object to move it forward instead of transforming it. It worked the way I wanted it to. Thanks.

Alternately, you can use Rigidbody.MovePosition() as a way to move an object with a rigidbody to a specific position, while still handling collision detection properly.

1 Like