How can I get a rotated plane object to move along the default terrain (move in the x-z plane) using WASD? The plane is perpendicular to the terrain.
I did the following steps below, and I am getting really screwy behavior when trying to move the plane. Once I make a simple modification to the stock FPSController (see bottom), the plane object will only move in the -z direction (via the S key) once I press and hold A or D. Even weirder, W does not move the plane in the +z direction if I hold A or D. Pressing W or S by themselves does nothing.
I did the following (and nothing else, starting from scratch) to get that far:
- Create the default terrain
- Create a plane gameobject
- Rotate it perpendicular to the terrain (-90 in X for me)
- Add the CharacterMotor script and FPSInputController (from Standard Assets/Character Controllers/Sources/Scripts) to the plane gameobject
- Add SmoothFollow to the Main Camera and add the plane as the target
From here, I changed one line in FPSInputController.js to change the W/S keys from up/down(y) to in/out(z), as my plane is rotated to be perpendicular to the terrain:
motor.inputMoveDirection = transform.rotation * directionVector;
to
motor.inputMoveDirection = directionVector;
where
var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
At first, I worried that I was trying to do the impossible, but the plane does actually move in -z if you also get it moving in the x direction, so you'd think generic movement in Z would be possible for the plane. Is there another method to accomplishing this?