- Home /
Question by
peteratef · Jun 12, 2017 at 09:13 AM ·
velocity2d-physicsrigidbody.addforcerigidbody.velocity
How to Rotate 2d Object with constant speed ?
Hi there,
I have a problem with a game i want to make. i am trying to make the small circle to rotate around the center circle.
How can i add force or set Velocity to make it rotate at constant speed ?
void Update ()
{
position = transform.position;
float ang = AngleBetweenVector2 (org, -position);
transform.rotation = Quaternion.AngleAxis(ang+90, Vector3.forward);
Debug.Log (body.velocity.normalized);
}
private float AngleBetweenVector2 (Vector2 vec1, Vector2 vec2)
{
Vector2 diference = vec2 - vec1;
float sign = (vec2.y < vec1.y) ? -1.0f : 1.0f;
return Vector2.Angle (Vector2.right, diference) * sign;
}
ask.png
(75.4 kB)
Comment
Best Answer
Answer by Dyougi · Jun 12, 2017 at 11:58 AM
I would do as following:
Create an empty GameObject and set his position at the center of your big circle. Then set the little circle as a child of it. After that, you just have to apply a constant rotation on the empty GameObject you just created.
void Update()
{
transform.Rotate(Vector3.forward * speedRotate * Time.deltaTime);
}
that's a great idea it can save me a lot of code in other place.
thanks