- Home /
Question by
Luvs2Dummy · Mar 05, 2014 at 06:24 PM ·
movementanimatoranimator controller
Moving an animated object's animator instead of the object?
Hey, so I had a character that I could move and rotate with the arrow keys working just fine. However, when I animated the object it will no longer move. It will still rotate, but that's it. The components of the object are children of a GameObject that contains an Animator with a controller. Here is the movement script:
using UnityEngine;
using System.Collections;
public class movement : MonoBehaviour {
public float moveSpeed = 10f;
public float turnSpeed = 400f; //move speed and rate of turning
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
print (transform.position.x + ", " + transform.position.y);
if (Input.GetKey (KeyCode.UpArrow))
transform.Translate (Vector3.down * moveSpeed * Time.deltaTime);
if (Input.GetKey (KeyCode.DownArrow))
transform.Translate (Vector3.up * moveSpeed * Time.deltaTime); //move back and forward over time
if (Input.GetKey (KeyCode.LeftArrow))
transform.Rotate (Vector3.back, -turnSpeed * Time.deltaTime); //rotate left and right over time
if (Input.GetKey (KeyCode.RightArrow))
transform.Rotate (-Vector3.forward, turnSpeed * Time.deltaTime);
}
}
I think the solution is that I need to access the animator component and move its position, but I haven't had any luck with that, so I reverted to my old script for simplicity.
Thanks
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613135440im_/https://answers.unity.com/themes/thub/images/avi.jpg)