- Home /
[Solved] How to calculate transition from movement speed to rotation speed?
Hi all,
At this moment, I am trying to figure out how to calculate the rotation speed for my game. In the game, you can move a forward and upon touching the screen, you transition into the rotation state.
When in rotation state, you rotate around a given point with an offset. This is done by the following code:
currentGrappleAngle += grappleSpeed;
targetPosition.x = Mathf.Cos(currentGrappleAngle * Mathf.Deg2Rad) * radius;
targetPosition.z = Mathf.Sin(currentGrappleAngle * Mathf.Deg2Rad) * radius;
targetPosition.y = rb.position.y;
targetPosition += grapplePoint.position;
rb.MovePosition(targetPosition);
Here, the position is calculated using (co)sines which get the current angle. The result of this is then multiplied by the offset (radius) to get the required position.
Now, the grappleSpeed is the thing that determines how fast this rotating happens. The problem lies at how this is calculated. At this moment this is being calculated the following way:
(currentSpeed - radius) * Time.deltaTime;
Current speed is the magnitude the rigidbody travels, where radius is the offset distance. This does not work as I want however. Most of the time, you can see a slight difference in speed when transitioning, but other times, it clearly has a different speed.
Does anyone with better math skills than me have an idea of how I can fix this problem? Thanks in advance!
Answer by JenoahKers · Dec 14, 2020 at 09:52 PM
Hi all,
In the meantime I had a shower thought of how I could reformulate my question and I found the answer! Basically, if you want to convert velocity to angular velocity, you take you velocity and divide it through the radius. (ω = v / r).
To convert it back, just reverse it and do angular velocity times the radius (v = ω * radius).
Hope this helps anyone!
Your answer
Follow this Question
Related Questions
Uniform rotation - uniform lerp 1 Answer
Set a relative (custom) speed to a rotation 1 Answer
A constant speed rotation finishing with a correct angle. 2 Answers
Speed limit? 2 Answers