- Home /
How do i get the cube to turn when up and right or left arrow is pressed?
Right now, the cube is moving up, down, left and right but it doesnt turn as its moving in the direction its going.
I want the cube to turn when its moving in the direction its heading towards.
the cube is on another cube that is flat and larger on the Y axis, so only X and Z are free.
This is an easy fix, but in order to give you an accurate answer, we have to see your code.
public class SnakeScript: $$anonymous$$onoBehaviour {
public float SnakeSpeed = 10f;
public GameObject Body;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
$$anonymous$$ove ();
}
void $$anonymous$$ove()
{
transform.Translate(SnakeSpeed * Time.deltaTime *Input.GetAxis("Horizontal"),0,0);
transform.Translate(0,0,SnakeSpeed * Time.deltaTime *Input.GetAxis("Vertical"));
}
void OnCollision(Collision col)
{
if(col.gameObject.tag == "Egg")
{
Destroy(col.gameObject);
AddBody();
}
}
void AddBody()
{
}
}
this is pretty much all i got now
Answer by robertbu · Jun 18, 2013 at 06:05 AM
Replace your Move() with this:
void Move()
{
Vector3 v3 = new Vector3(SnakeSpeed * Time.deltaTime *Input.GetAxis("Horizontal"),0,SnakeSpeed * Time.deltaTime *Input.GetAxis("Vertical"));
transform.Translate(v3, Space.World);
if (v3 != Vector3.zero)
transform.rotation = Quaternion.LookRotation(v3);
}
Your answer
Follow this Question
Related Questions
Is it okay to use ForceMode.VelocityChange in Update()? 1 Answer
Problem with Rigidbody Parent/Child Relationship with "Teeter Totter" 0 Answers
Stop child colliders from applying force individually 0 Answers
Influence of the collision on the other object 0 Answers
Smooth Player Ball Rolling 1 Answer