- Home /
Question by
MarceloCosta_GamesBR · Jul 26, 2014 at 11:25 AM ·
rotationobjectscalculate
How Calculate Rotation Y two objects?
i need calculate rotation Y of two objects for make the player ball control
get Rotation Y of ray get Rotation Y of Player and calculate an rotation less other
somebody know something about it?
Comment
I'm having a hard time understanding that. Could you describe what you're trying to do in more detail? Pictures or diagrams might help.
Answer by Hullu · Jul 26, 2014 at 02:21 PM
I'm not sure if i understood you correctly, but do you mean like football game? So when the player is facing the ball something happens.
If im right, one way to do this is with http://docs.unity3d.com/ScriptReference/Vector3.Angle.html
Example (with distance):
direction = transform.position - ball.position;
angle = Vector3.Angle(transform.forward, direction);
distance = direction.magnitude;
if (Mathf.Abs(angle) < 90 && distance < 1)
print("target is in front of me");