- Home /
using mouse controls to navigate
Is it there a script or settings that I can used to be able to navigate around the game environment using mouse controls? Id like to left click and drag to walk around, right click and drag to elevate and use the middle button to look around.
Answer by Bravini · Oct 20, 2010 at 07:06 PM
you can use the basic movement scripts and change their virtual inputs on Edit>Project Settings> Input a tab will ope on the right side with the presetted inputs, it`s easy to figure from there.
http://unity3d.com/support/documentation/ScriptReference/Input.html
something like this:
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
var turnSpeed = 2.0;
private var moveRotation = Vector3.zero;
function Update() {
if (Input.GetButtonDown("Fire1") {
// left mouse is clicked, so recalculate movedirection directly from axes
moveDirection = new Vector3(0, 0, Input.GetAxis("Mouse Y"));
moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed; moveRotation = new Vector3(0,Input.GetAxis("Mouse X"),0);
transform.Rotate (moveRotation* turnSpeed);
} }
thanks, i tried that and the problem with it is that i cannot add a combination of actions/buttons like holding the mouse button down and dragging to a specific direction to move. Is it maybe possible to edit the FPSWalker script so that it doesn't use the keyboard to move left or right but uses the left mouse button?
thanks again, where do i add the script? sorry if i cant catch on faster, i just started using unity recently.
Place it on the highest gameobject in the hierarchy of your character. a good place to start is http://unity3d.com/support/resources/ there are lots of useful stuff and examples for common and some obscure algorhytms