I have a FPS character and a sphere. I’ve put walls around the character which follow to position of the character, so that the player is always in a small tube, surrounded by walls:
void Update () {
Vector3 innerWalls = gameObject.transform.position;
Vector3 player = GameObject.Find ("playerController").transform.position;
Vector3 temp;
temp.x = player.x;
temp.z = player.z;
temp.y = innerWalls.y;
gameObject.transform.position = temp;
}
Next, I’ve disabled the mesh renderer so that the walls are invisible for the player.
The reason I’ve done this, is because I want to make it so that if the player would go near the sphere, the walls would hit the sphere and the player should be able to “move” to sphere (basically the walls should be pushing it forward).
This doesn’t work, unfortunately. After some flickering, the sphere passes through the walls. If I would make the sphere move, it’s unable to go through walls be itself, but when the player is moving the walls, apparently it is.
I’m using a rigidbody on the sphere, but I disabled gravity on it because it floats in the air. I’m not using a rigidbody on the walls, only a collider. I tried adding a rigidbody to the walls too, but that makes the walls tip and possibly fall over after hitting the sphere. If you choose to Freeze the rotation of the walls, the sphere again passes through the walls.
I haven’t applied force because this would make it possible to “kick” the sphere away when hitting it, while it should just be pushed away (sticking to the wall).
Anyone knows what’s causing this issue or knows how to fix this?