Search Unity

FPS1 1.3 Basic Walking/Running problem

Discussion in 'Scripting' started by Warb, Feb 3, 2013.

  1. Warb

    Warb

    Joined:
    Feb 3, 2013
    Posts:
    2
    Did everything the instructions told me to, except for the Player Movement Script I got from here:
    http://forum.unity3d.com/threads/115330-ETeeskiTutorials-Scripts-up-to-FPS1.16

    This is my full script:

    var walkAcceleration : float = 5;

    var walkAccelAirRacio : float = 0.1;

    var walkDeacceleration : float = 5;

    @HideInInspector

    var walkDeaccelerationVolx : float;

    @HideInInspector

    var walkDeaccelerationVolz : float;



    var cameraObject : GameObject;

    var maxWalkSpeed : float = 20;

    @HideInInspector

    var horizontalMovement : Vector2;



    var jumpVelocity : float = 20;

    @HideInInspector

    var grounded : boolean = false;

    var maxSlope : float = 60;



    function LateUpdate ()

    {

    horizontalMovement = Vector2(rigidbody.velocity.x, rigidbody.velocity.z);

    if (horizontalMovement.magnitude > maxWalkSpeed)

    {

    horizontalMovement = horizontalMovement.normalized;

    horizontalMovement *= maxWalkSpeed;

    }

    rigidbody.velocity.x = horizontalMovement.x;

    rigidbody.velocity.z = horizontalMovement.y;



    if (grounded){

    rigidbody.velocity.x = Mathf.SmoothDamp(rigidbody.velocity.x, 0, walkDeaccelerationVolx, walkDeacceleration);

    rigidbody.velocity.z = Mathf.SmoothDamp(rigidbody.velocity.z, 0, walkDeaccelerationVolz, walkDeacceleration);}



    transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentYRotation, 0);



    if (grounded)

    rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * Time.deltaTime);

    else

    rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * walkAccelAirRacio * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * walkAccelAirRacio * Time.deltaTime);



    if (Input.GetButtonDown("Jump") grounded)

    rigidbody.AddForce(0,jumpVelocity,0);

    }



    function OnCollisionStay (collision : Collision)

    {

    for (var contact : ContactPoint in collision.contacts)

    {

    if (Vector3.Angle(contact.normal, Vector3.up) < maxSlope)

    grounded = true;

    }

    }



    function OnCollisionExit ()

    {

    grounded = false;

    }




    When I try and move, nothing works. I looked at the inspector and it says that I was moving REEEEALLY slowly. Please, help.
     
  2. squared55

    squared55

    Joined:
    Aug 28, 2012
    Posts:
    1,818
    Increase the acceleration.
    Alot.