FPS input controller

Hey i just updated to Unity 3 and for some reason none of my Controller scripts seem to work. So im just going to use the First Person controller that comes with unity. I want to make a change to it however, I want to make it so that when you press s,d or the right or left arrow, he rotates in those directions, instead of moving in that direction. Can anyone help please?

private var motor : CharacterMotor;

// Use this for initialization
function Awake () {
    motor = GetComponent(CharacterMotor);
}

// Update is called once per frame
function Update () {
    // Get the input vector from kayboard or analog stick
    var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));     
    

    
    if (directionVector != Vector3.zero) {
        // Get the length of the directon vector and then normalize it
        // Dividing by the length is cheaper than normalizing when we already have the length anyway
        var directionLength = directionVector.magnitude;
        directionVector = directionVector / directionLength;
        
        // Make sure the length is no bigger than 1
        directionLength = Mathf.Min(1, directionLength);
        
        // Make the input vector more sensitive towards the extremes and less sensitive in the middle
        // This makes it easier to control slow speeds when using analog sticks
        directionLength = directionLength * directionLength;
        
        // Multiply the normalized direction vector by the modified length
        directionVector = directionVector * directionLength;
    
    }
    
    // Apply the direction to the CharacterMotor
    motor.inputMoveDirection = transform.rotation * directionVector;
    motor.inputJump = Input.GetButton("Jump");
}

// Require a character controller to be attached to the same game object
@script RequireComponent (CharacterMotor)
@script AddComponentMenu ("Character/FPS Input Controller")

When you add a First Person Controller, you actually add a:

Camera
Capsule
Character Motor script
Mouse Look script
FPS Input Controller

The FPS Input Controller controls left/right/forward/backwards/jump movement, so if you don’t want that, simply remove or disable the script. The Mouse Look script controls rotation, so that’s the one you’ll be interested in.

For a first stab, you could try simply re-mapping MouseX and MouseY to the keyboard via Eidt | Project Settings | Input. If that doesn’t work or doesn’t work well enough, check out the Input class:

The best method to use is probably via GetButton(), as this allows players to remap their controls as in most games. Click on Edit | Project Settings | Input | Axes to get the logical names of the various buttons.

If that’s too intimidating and re-mapping isn’t necessary, GetKeyUp() and GetKeyDown() are available and those use KeyCodes which are quite straightforward. Eg, KeyCode.A = pressing the A key, KeyCode.B = pressing the B key, etc. If that’s too hard, well, I can do custom programming for a fee. :slight_smile:

Good luck!

@SweetRevenge did you ever figure this out?

if you wanna get a rotation
i suggest to change MouseLook script.

You can edit “Get the input vector from kayboard or analog stick” (update function) from FPSInput Script and then add var directionVector = new Vector3(0, 0, Input.GetAxis(“Vertical”));

For Rotation You can add new script or add mouse lookup

using UnityEngine;
using System.Collections;

public class PlayerMove : MonoBehaviour {

public float turnSpeed=50f;

void Update(){

if(Input.GetKey(KeyCode.LeftArrow))
transform.Rotate (Vector3.up,-turnSpeed*Time.deltaTime);

if(Input.GetKey(KeyCode.RightArrow))
transform.Rotate (Vector3.up,turnSpeed*Time.deltaTime);

}
}