0
\$\begingroup\$

The animations are playing fine, however I can't manage to move my character. My script:

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

    public float turnSmoothing = 20f;
    public float speedDampTime = 0.1f;
    public float jumpHeight = 8.0f;

    private Animator anim;
    private Rigidbody rb;
    // Use this for initialization
    void Start () {
        anim = GetComponent<Animator>();
        rb = GetComponent<Rigidbody>();

    }

    // Update is called once per frame
    void Update () {

    }

    void FixedUpdate()
    {
        float h =- Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        MovementManagement(h,v);

    }

    void MovementManagement (float horizontal, float vertical)
    { 
        if (horizontal != 0.0f || vertical != 0.0f)
        {
            anim.SetBool("Move", true);
            anim.SetFloat("Speed", 6.0f, speedDampTime, Time.deltaTime);
            Rotating(horizontal, vertical);

        }
        else
        {
            anim.SetFloat("Speed", 0.0f);
            anim.SetBool("Move", false);
        }

    }

    void Rotating (float horizontal, float vertical)
    {
        Vector3 targetDirection = new Vector3(horizontal, 0.0f, 0,0f); //2.5D I just want to move on the x-axis atm
        Quaternion targetRotation = Quaternion.LookRotation(targetDirection, Vector3.up);
        Quaternion newRotation = Quaternion.Lerp(rb.rotation, targetRotation, turnSmoothing * Time.deltaTime);
        rb.MoveRotation(newRotation);
    }

}

My character's inspector:

enter image description here

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Well, you only change the rotation of the rigidbody, not the position. See the documentation http://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html

\$\endgroup\$
3
  • \$\begingroup\$ Thanks, but that's not working properly. I've another object and it's working fine without that. Moreover, if I use the rb.MovePosition, the movement is very slow. Thanks for your answer. Edit: Well, I've multiplied delta time *10 and the speed seems good...thanks! \$\endgroup\$ Commented Feb 20, 2016 at 21:03
  • \$\begingroup\$ I can't see the other object, so i can't judge that. \$\endgroup\$
    – Eashi
    Commented Feb 20, 2016 at 21:08
  • \$\begingroup\$ The other object is the Ethan example model \$\endgroup\$ Commented Feb 20, 2016 at 21:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .