- Home /
Possible To Add Move Functions To Camera?
Hello,
I have a Orthographic camera in my scene, right now, all it does (movement wise) is zoom in and out via the scroll wheel.
Is it possible to add Left, Right, Up, Down functions to the camera too? Maybe even rotation? (< and > keys for rotation?)
I do not want to control the camera movement with the mouse (unless the mouse moves towards the edge of the screen - thus causing the camera to move in that direction -- but this isn't important right now)
Point in the right direction?
Cheers
So would you want it to be like, arrow keys/WASD to move the camera?
If so, couldn't you add FPS Walker script to the camera, then you can move the camera around, and then you can take out the jump script and all that, so it just moves around wen you push the keys... Does that work or not quiet? (BTW, your TD game looks fun =) )
I think he wants it so that the camera doesn't have gravity.
I literally just want it so when I press A the camera will move left, or D then the camera will move right. Thanks
Answer by oliver-jones · Dec 11, 2010 at 01:50 PM
Figured it out, quite simple really:
transform.Translate(0, Input.GetAxis ("Vertical") * rotateSpeed, 0);
transform.Translate(Input.GetAxis ("Horizontal") * rotateSpeed, 0, 0);
Thanks anyway.
that's kind of what i'm doing, O.J., but i just have it automatically moving the cam with the Translate function, but that's smart to use inputs.... very smart! 1+
Answer by JesusChristChangedMe · Dec 09, 2010 at 09:15 PM
Try this script.
var speed = 3.0;
var rotateSpeed = 3.0;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
}
@script RequireComponent(CharacterController)
Nearly - Two problems though. First one being that it falls (as if it has a rigidbody : gravity) towards the terrain. And the movement is more of a tilt, rather than a move left/right.
Remove the @script RequireComponent(charactercontroller) and that should do it
Tried it - but its still 'rotating' the camera, rather than moving the position. W and S don't even do anything?