Maze Rotation collision problem (17760)

I'm creating a first person 3d maze game where the player can rotate the level itself to walk along the walls/ ceiling. I have mesh colliders set up for the walls of the maze as well as box colliders for the cube the maze is in. I am also using the first person controller for the player. At first everything seems to work fine; I stay on the ground and I don't walk through walls. However, when I try to rotate the level it results in either the player being flung out of the cube or the player falling through the cube, like completely ignoring the colliders I have set up.


Rotation code for cube

var eulerAngleVelocity : Vector3 = Vector3 (0,0,100);
function FixedUpdate () {

if (Input.GetKey ("z"))
    // spin the player around the world origin at 'RotateSpeed' degrees/second.
var deltaRotation : Quaternion = Quaternion.Euler(eulerAngleVelocity * Time.deltaTime);
rigidbody.MoveRotation(rigidbody.rotation * deltaRotation);
}

1 Answer

1

Non kinematic Rigidbodies have to be moved/rotated by forces. If you rotate it with transform.rotation or transform.localRotation and i guess also transform.Rotate it will ignore the physics because you set the rotation to a fix end rotation. Unity don't know in which direction you rotated the object.

Use Rigidbody.AddTorque for non kinematic rigidbodies and Rigidbody.MoveRotation for kinematic rigidbodies. I would recommend to use a kinematic rigidbody because i don't think you want physic feedback on your rotating level.

If you want to use a non kinematic rigidbody, i think you still can use Rigidbody.MoveRotation but as i said the rotation can be blocked or altered by others.

Never forget: non kinematic rigidbodies are designed to simulate the real world.

Archimedes:

Give me a place to stand, and I shall move the earth with a lever


edit

var eulerAngleVelocity : Vector3 = Vector3 (0,0,100);
function FixedUpdate () {
    if (Input.GetKey ("z")) {
        // spin the player around the world origin at 'RotateSpeed' degrees/second.
        var deltaRotation : Quaternion = Quaternion.Euler(eulerAngleVelocity * Time.deltaTime);
        rigidbody.MoveRotation(rigidbody.rotation * deltaRotation);
    }
}

You missed to put your code in a block. You if statement just cares about the variable deltaRotation. I'll add the correct script to my answer

It works in my testing scene. It's not that big but in general the same. I guess the problem is that you don't rotate the "world" around your player. You rotate around the worlds pivot and therefore the character get pushed heavily by some walls because the position relative to the outer world get shifted due to rotation.

Just to show you that it is possible ;) http://www.kongregate.com/games/SophieHoulden/sarahs-run-preview

If I would create such a game i would either: keep the character fixed and only move&rotate the world (rotate around the players pivot) or (which i think is used in Sarah's run) don't use a CharacterControler and leave the world as it is. Gravity is just a force that you apply to your character, the direction doesn't matter ;). So the ground is where you want but a CharacterController can't be tilted (global y always up) so just use a rigidbody with a CapsuleCollider. It doesn't make much difference you just need a bit more movement/collision handling.