I have two objects. One object is in the layer Wall, the other in MovingThroughWalls.
Below is a script I use to move the object through the wall for testing.
using UnityEngine;
using System.Collections;
public class Testmoving : MonoBehaviour {
private Vector3 basePosition;
private bool moveLeft = true;
public float moveX = 4.0f;
public float speed = 2.4f;
// Use this for initialization
void Start () {
basePosition = transform.position;
}
// Update is called once per frame
void FixedUpdate () {
if (moveLeft) {
collider.transform.Translate(speed * Time.fixedDeltaTime, 0.0f, 0.0f);
if (collider.transform.position.x > basePosition.x + moveX)
moveLeft = false;
} else {
collider.transform.Translate(-speed * Time.fixedDeltaTime, 0.0f, 0.0f);
if (collider.transform.position.x < basePosition.x - moveX)
moveLeft = true;
}
}
}
The Wall has a boxcollider and nothing more and the MovingThroughWalls object also has a boxcollider.
Below is my configuration for the physics.
For some reason my OnCollisionEnter(Collision collision) (to be clear) on the wall doesn’t fire. I am printing a simple string to see if it works.
Is there something I’m doing wrong here? Any help would be great…