There is a cube with a boxing collider. When this cube moves, it passes through walls (which also have a boxing collider). Cube code

public class RocketMovement : MonoBehaviour { public float speed = 3.0f; private float deltaX; private float deltaZ; private Component collider; // Use this for initialization void Start() { collider = this.GetComponent<BoxCollider>(); } // Update is called once per frame void Update() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); this.transform.position = new Vector3(ray.GetPoint(10f).x, this.transform.position.y, ray.GetPoint(10f).z); } } 

    1 answer 1

    You have no physics here. You simply move the object to a new position. In order for physics to function, it is necessary to hang RigidBody on an object and apply forces to it.

    • Added RigidBody - the same. - Yaktens Teed
    • Object move using Rigidbody.AddForce ? If you continue to reposition through this.transform.position = new Vector3(ray.GetPoint(10f).x, this.transform.position.y, ray.GetPoint(10f).z); then physics still won't work. - KingPeas
    • I'm trying to move an object using AddForce - it just disappears - Yaktens Teed
    • Throw a link to the project I will try to see, I can’t offer anything more to vskidku - KingPeas
    • Another couple of typical things: Rigidbody.AddForce() should be done in FixedUpdate() , instead of Update() . Gravity needs to be turned off, otherwise it may disappear because of this, simply by quickly falling off the frame boundary. - Maxim Kamalov