- Home /
Moving a rotated plane in x+z directions with WASD? (bizarre behavior)
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?
Answer by yevoc · Apr 04, 2011 at 06:22 PM
Making a cube instead of a plane and adding the standard controllers without modifying the scripts seems to work. Shrinking one of the cube dimensions to near zero gets the same effect done and allows for WASD movement along the terrain.
I suppose the plane doesn't work because it only exists in 2 dimensions, and I needed it to move in the 3rd dimension.
While this cube solution has its texture show up on two sides instead of one for the plane, I can work around that by masking with multiple cubes.