converting degrees per second into speed
Hello, I'm currently in the process of tying to make several objects rotate around a central point at the same speed. To do this, I am using Transform.rotateAround. The issue I'm having is that Transform.rotateAround uses degrees per second, rather than a normal speed variable. Because of this, the speed increases as the object gets farther away from the center point. I want the objects to stay the same speed, no matter where the object is relative to the point. Does anyone know how to do this?
Answer by Ermiq · Mar 04, 2021 at 07:22 PM
The title says you want to convert degrees into speed, but your post actually says you need to convert the speed into degrees. Because you already know how fast the objects should move around the orbit, but you don't know how much degrees to put into the RotateAround
.
Do I understand it right?
If so, pretty simple math here. I'm not gonna use Sins and Tans, because I'm too dumb for that, so here's how I would do it in a simplified way:
float desiredSpeed = 10f; //meters per sec
float distanceToOrbitCenter = Vector3.Distance(transform.position, centerObject.position);
float orbitLength = 2 * Mathf.PI * distanceToOrbitCenter; // Circle length from school: L = 2 * Pi * R
float metersInOneDegreeAroundCurrentOrbit = orbitLength / 360f;
float speedToDegrees = desiredSpeed / metersInOneDegreeAroundCurrentOrbit;
transform.RotateAround(centerObject.position, Vector3.up, speedToDegrees * Time.deltaTime);
@Ermiq, sorry I took so long to respond. I've created a test script, and it works perfectly. Thanks!
Your answer
Follow this Question
Related Questions
Teleport 2D Character on TriggerEnter 2 Answers
Making text appear by pressing a button, only when player is close to the object 1 Answer
Help with changing bool over time to play animation 1 Answer
Object with rigidbody2D doesn't move when it's supposed to, 0 Answers
Why is my knockback direction script inconsistent with it's knockback direction? 1 Answer