Sunday 10 April 2011

Rotating the world relative to the direction of the player


The next step was to make it so that the "shift button" turned the world forward, relative to the direction the player is facing. I modified the script slightly to alter the rotation direction based on the character's direction, which worked, however it highlighted an issue in the control of the gravity. By having the world rotate on a constantly changing axis it becomes extremely confusing to put gravity in the desired direction, especially when holding the "shift button" rotates the world gradually for as long as the button is held. I need to find a way, in which the player can flip gravity without messing up the axis. Possibly by having rotations in 90 degree increments, so that things don't become too confusing for the player.

var shiftKey : KeyCode;

function Update() {
if( Input.GetKey( shiftKey) )
{
////rotate the world forward
transform.RotateAround (GameObject.Find("3rd Person Controller/Bip001").transform.TransformPoint(Vector3.zero), GameObject.Find("3rd Person Controller/Bip001").transform.TransformPoint(Vector3(0, -1, 0)), 90 * Time.deltaTime);
}
}

New script for player-relative rotation

No comments:

Post a Comment