# How to convert RotateAround speed to directional speed in Unity?

I am currently using

transform.RotateAround(transform.position, Vector3.forward, degreesPerSecond * Time.deltaTime)


to make an object rotate around another object. This works well, but I want to make the object stop rotating around and instead move in a certain direction at the same speed that it was rotating. However, I can not figure out how to convert the degreesPerSecond into a directional speed.

My goal is to have something like this:

if(rotating) {
transform.RotateAround(transform.position, Vector3.forward, degreesPerSecond * Time.deltaTime)
} else {
transform.position += transform.right * DegreesToDirectionalSpeed(degreesPerSecond ) * Time.deltaTime;
}

float DegreesToDirectionalSpeed(int degrees) {
// Code that I don't know goes here
}


Any tips on how to achieve this?

Romen's answer is correct regarding the physics concepts involved.

In terms of implementation in Unity, you can do it like this:

Transform center;
float degreesPerSecond;
Vector3 axis = Vector3.forward;
bool hasReleased;
Vector3 releaseVelocity;

// Call this when you want to let the sling loose to fly in a straight line.
public void Release() {
Vector3 offsetFromCenter = transform.position - center.position;

Vector3 travelDirection = Vector3.Cross(axis, offsetFromCenter).normalized;

hasReleased = true;
}

void Update() {
if(!hasReleased) {
transform.RotateAround(center.position, axis, degreesPerSecond * Time.deltaTime);
} else {
transform.Translate(releaseVelocity * Time.deltaTime, Space.World);
}
}


You are looking for something called the tangential velocity vector.

A point on a rotating object at r distance away from the center of rotation will be moving a speed equal to r * ω
Where ω is the angular velocity of the object in radians per second.

If you can determine the distance between the entity and the point it is rotating around you simply multiply the angular speed by that distance.
Note that this only calculates the speed of the object, its direction will be determined by the tangent to the circle at that point.

An explanation of angular velocity can be found here:
http://hyperphysics.phy-astr.gsu.edu/hbase/rotq.html