Search Unity

Editing Character Controller

Discussion in 'Scripting' started by Vym, Mar 23, 2014.

?

Was this helpful/interesting?

Poll closed Apr 25, 2014.
  1. Yes

    0 vote(s)
    0.0%
  2. No

    0 vote(s)
    0.0%
  3. Sortof

    0 vote(s)
    0.0%
  1. Vym

    Vym

    Joined:
    Mar 16, 2014
    Posts:
    7
    hello, Here is my FPSInputControler.js:
    Code (csharp):
    1. private var motor : CharacterMotor;
    2.  
    3. // Use this for initialization
    4. function Awake () {
    5.     motor = GetComponent(CharacterMotor);
    6. }
    7.  
    8. // Update is called once per frame
    9. function Update () {
    10.     // Get the input vector from keyboard or analog stick
    11.     var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
    12.    
    13.     if (directionVector != Vector3.zero) {
    14.         // Get the length of the directon vector and then normalize it
    15.         // Dividing by the length is cheaper than normalizing when we already have the length anyway
    16.         var directionLength = directionVector.magnitude;
    17.         directionVector = directionVector / directionLength;
    18.        
    19.         // Make sure the length is no bigger than 1
    20.         directionLength = Mathf.Min(1, directionLength);
    21.        
    22.         // Make the input vector more sensitive towards the extremes and less sensitive in the middle
    23.         // This makes it easier to control slow speeds when using analog sticks
    24.         directionLength = directionLength * directionLength;
    25.        
    26.         // Multiply the normalized direction vector by the modified length
    27.         directionVector = directionVector * directionLength;
    28.     }
    29.    
    30.     // Apply the direction to the CharacterMotor
    31.     motor.inputMoveDirection = transform.rotation * directionVector;
    32.     motor.inputJump = Input.GetButton("Jump");
    33. }
    34.  
    35. // Require a character controller to be attached to the same game object
    36. @script RequireComponent (CharacterMotor)
    37. @script AddComponentMenu ("Character/FPS Input Controller")
    38.  
    I want to make it so that if I press "w" twice in 0.15 seconds, the speed is multiplied by 2; If you press space in 0.15 seconds, you can double jump. Also, how can I make the camera move so the character looks like it is walking?(only when its walking.) Thank you so much.
     
    Last edited: Mar 25, 2014