- Home /
making an object face the direction its moving
hey everyone, ok so i have a ball that is a child to another ball that rolls around the scene. however this one has a freeze rotation script added as i dont want this ball to roll around, what i do want however is the ball to face the direction its moving.
the script i'm using is as follows var mySphere : GameObject;
function Update()
{
gameObject.transform.position = mySphere.transform.position;
transform.eulerAngles = Vector3(0, 0, 0);
}
yeah sorry, ok so i have lets say ball "A" which players can roll around the level, Ball "B" is a child of Ball "A" and has a freeze rotate script so it stays standing and doesnt roll around like ball "A". what i want is the sphere's UP axis rotates to face the direction Ball A is moving. hope that helps, if not i can post some pics to show what i mean
var mySphere : GameObject;
function Update()
{
gameObject.transform.position = mySphere.transform.position;
transform.eulerAngles = Vector3(0, 0, 0);
mySphere.transform.rotation = Quaternion.LookRotation(Vector3.forward, Vector3.up);
}
tried that but still noting =S
Vector3.forward is in world space. Vector3.forward will always be the same. Try either transform.forward or transform.TransformDirection(Vector3.forward).
What are you using to move the ball?? Is it a rigidbody using velocity or force, or is it just a transform using translate or position+?
If you rotate something on the Z axis, it will "roll" left and right, since you'd be rotating around the forward axis. To make it actually "look" left / right, use the Y axis. X axis rotation would make it look up and down. $$anonymous$$aybe a screenshot and your full code would help me better understand what you're trying to do.
Answer by clunk47 · Sep 21, 2013 at 06:16 PM
I don't know if I understand your question fully, but try this. If this isn't what you're looking for, please give some more detail on the issue.
transform.forward = mySphere.transform.forward;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Object Rotation/Character Speed 1 Answer
Can This be done Easier? Duplicating gameobjects 1 Answer
NullReferenceException 0 Answers
How you find an Object 1 Answer