Character Rotation with fixed 3rd person Camera?

I’m trying to make the movement and rotation of my player character work without mouse input, but as it stands now she just kind of slides around without changing direction. This is what’s going on in the character controller code.

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

    public float speed = 18;

    private Rigidbody rig;

    // Use this for initialization
    void Start ()
    {
        rig = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update ()
    {
        float hAxis = Input.GetAxis("Horizontal");
        float vAxis = Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(hAxis, 0, vAxis) * speed * Time.deltaTime;

        rig.MovePosition(transform.position + movement);

    }
}

(I have absolutely no experience with code and am trying to learn as I go, so trying to puzzle through this on my own is going about as quick as you’d expect. Sorry if this is an easy fix, google really wasn’t helping me.)

Use MoveRotation(), like you’re using MovePosition(), to rotate your rigidbody. You can build your rotation using Quaternion.LookRotation() using your movement direction.

1 Like

Awesome, thank you so much!