- Home /

# Translating Speed into rotation degress\sec

Hi all!

If I understand correctly, then transform.rotatearound uses three variables. The first is a transform to orbit, the second is the direction of the rotation and the thid (which is what I wish to discuss) is the speed of the rotation calculated via degrees per second (or whatever timeframe you choose).

What I wish to ask is - Say that an object moves in a certain speed and is then oredered to orbit another object via the RotateAround command. How to I assign it a correct degrees per sec value that will maintain it's current speed perfectly and (if needed) translate it back into speed should I wish it to lose its' orbit?

I know it has something to do with the distance between them but my brain just can't figure out the physics...

Lastly, and on a related note - the Direction. How do I make sure that, given the velocity vector of an object A and it's relation in space to object B, said object A enters orbit in a direction that fits its' inital velocity. I managed to figure out a very VERY rough system with many "if" clauses to figure out all possible cases for this but I was wondering if maybe there is a more elegant approach :)

much obliged!

**Answer** by moonstruck
·
Jun 27, 2013 at 01:57 PM

The linear velocity v = w * R, where w is the angular velocity and R is the radius, thus w = v / R. Converting this from radians we have the formula for the velocity (degrees per second): w = 180 * v / ( pi * R ).

The rotation axis is [ v, ( B - A ) ], where B - A is the vector from the center of rotation to your object (they should not be collinear in order to get a non-zero axis). So you can rotate around Vector3.Cross( v, B-A ).normalized. If it goes in the wrong direction then change the sign of the vector. :)

I see... and how should I calculate v and R? vector3.magnitude on both (using the rigidbody.velocity for v and the difference between the positiong of the orbiting object and the gravity center for R)?

the formula turns out something entreiyl different from what I came up with so thank whatever diety is appropriate you came along, sir! :D

regarding the rotation axis, should I again use vector3.magnitude to calculate (B-A)? or is there a more fitting function?

many thanks!

You are welcome. :D

Yeah just use rigidbody.velocity as v (it is in meters per second). Don't normalize R because you need the original radius (not unit length) to get proper result.

Also there is no need to normalize B - A for the axis because you normalize the final cross product.

so which functions SHOULD I use to get R?

I think i'll just go out and ask for it bluntly - could you write a sample code of how this should all end up looking lik? because when I use 180*rigidbody.velocity*mathf.pi/vector3(A-B) it makes visual studio kinda go wwwwWWWHHHHHHAAAAT?

```
public Transform obj;
public Transform center;
...
Vector3 R = center.position - obj.position;
Vector3 v = rigidbody.velocity;
float w = 180 * v.magnitude / ( $$anonymous$$athf.PI * R.magnitude );
Vector3 axis = Vector3.Cross( v, R ).normalized;
```

Something like this. :)

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Distribute terrain in zones 3 Answers

[C#] Wall Bounce While Setting Velocity for a Racing Game? 0 Answers

Can't clamp velocity 3 Answers

Unity relative velocity limiting 0 Answers

Velocity Behavior Question 0 Answers