Unusual normalized vector effects on movement

I apologize beforehand if this is rudimentary or if I’ve repeated someone else’ question; I haven’t found any input on this particular problem yet.

A friend and I are putting together a custom character controller for our project. We are still handling basic movement but are getting strange results.

We have noticed that our code results in unresponsive movement in that the player will continue to move in a direction after the button has been released. Since we are using MovePosition rather than altering the object’s RigidBody’s velocity, this doesn’t make sense to us.

To top it off, we have noticed that if we do not use a normalized version of the vector we are using to do movement, the movement becomes far less “floaty.” We would like to keep our movement vectors normalized so we need to understand why this is happening. Any ideas?

using UnityEngine;
using System.Collections;

/*[RequireComponent (typeof (Animator))]*/
[RequireComponent (typeof (CapsuleCollider))]
[RequireComponent (typeof (Rigidbody))]

public class PlayerControllerCustom : MonoBehaviour
{
    Quaternion tarRot;
    Rigidbody rb;

    private float moveSpeed = 4.0f;

    private float inputX;
    private float inputZ;
    private int animInt;

    void Start ()
    {
        tarRot = transform.rotation;
        rb = GetComponent<Rigidbody>();
	}

    void Update() //All player Input should go here if possible
    {
        inputX = Input.GetAxis("Horizontal");  //Gets W/S Input for X Axis (built into Unity)
        inputZ = Input.GetAxis("Vertical");  //Gets A/D Input for Z Axis (build into Unity)
    }

	void FixedUpdate () //All Physics calculations should go here
    {
        Run();  //Calls to Run Method every FixedUpdate
        Crouch();  //Calls to Crouch Method every FixedUpdate
        Sprint();  //Calls to Sprint Method every FixedUpdate

	}

    /***************************************************/
    /*  ************* MOVEMENT METHODS ************* */

    void Run()  //Run with WASD (Built in Unity input: W/S for positive / negative Z axis values, A/D for negative / positive X axis values)
    {
        rb.MovePosition(transform.position + (transform.TransformDirection((inputX), 0, (inputZ)).normalized * moveSpeed * Time.deltaTime));
    }

    void Crouch()  //Crouch while Left Control is held down
    {
        if (Input.GetKey(KeyCode.LeftControl))
        {
            moveSpeed = 2.0f;
            rb.MovePosition(transform.position + (transform.TransformDirection((inputX), 0, (inputZ)).normalized * moveSpeed * Time.deltaTime));
        }

    }

    void Sprint()  //Sprint while Left Shift is held down and player is standing and only moving forward (no X axis or negative Z axis movement)
    {
        if (Input.GetKey(KeyCode.LeftShift) && inputX == 0 && inputZ > 0 && animInt == 0)
        {
            moveSpeed = 8.0f;
        }

        else
        {
            moveSpeed = 4.0f;
        }
    }
}

Thank you very much for your help.

Hi, “GetAxis” returns a value that is smoothed by Unity : read the manual about inputs and the “gravity” and “sensitivity” parameters. It’s nice but can introduce some sort of lag.

Using “GetAxisRaw” will return non-smoothed values. Depending on what effect you want, you may use the “raw” version or change the gravity + sensitivity parameters to your liking.