I want to set up a simple navigation game which has a first person fly through in space. The existing scripts for first person navigation only allow 2D motion in a terrian (turn left and right, go forward and backward) controlled by arrow keys and mouse. Is there any ways (existing scritps with some modification) for me to do it?
I think you are looking for the following:
Add the "Mouse Look" component to your camera.
Change the MaximumY to 90 and the minimum to -90 (this will allow you to look up and down)
Now add the FPSWalker Component to your Camera which will allow you to move around.
Change the script of the FPSWalker, change it from:
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
TO:
function FixedUpdate() {
// Calculate the move direction
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
controller.Move(moveDirection * Time.deltaTime);
}
This will enable you to move freely in 3D space by the arrow keys or the WASD keys.
Thank you very much for the answer. The scripts work well.
But as I press the arrow keys, the character goes forward, backward, left and right. Can I go up and down also? How to do it?
bro where can i get FPSWalker component please.
Removed Spam