- Home /
How to calculate an angle in radians based on a circular moving platforms Vector2 value
Hey,
I have an interesting problem I'm currently trying to solve for a feature in my game. I decided I wanted to be able to use circular moving platforms in my 2d platformer game.
This feature works great, I have a platform that moves in a circle around a center point and the player can jump and ride this no problem.
The platform works by measuring it's angle based on where it is around the center point and then positioning itself on the angle. So for 0 radians, the platform is directly above the center, and at 1pi radian it is directly below it. At 2pi radians it has completed a full circle.
What I'd like to do is to be able to have the platform calculate how far around this circuit it is based on its current vector2 position during the Start method. For instance, if the platform is placed below the center, and then I start the scene up, then I'd like it to calculate that its starting angle is 1pi radian. Does anyone know the best way of going about doing this?
As it stands, the angle defaults to 0 right now on start, so it always begins above the center point. It would improve my workflow though if I can get it to calculate its starting angle itself.
float PlatformLocalPosToAngle ( Vector2 vec ) => Mathf.Atan2(vec.y,vec.x) + Mathf.PI*0.5f;
If you change your platform's starting position to Vector2.right
then you can simplify it to just Mathf.Atan2(vec.y,vec.x)
.
Your answer

Follow this Question
Related Questions
2D 360 degress platformer example needed 0 Answers
Player stucken in the wall while jumping 2D 1 Answer
Replicating genesis Sonic's collision physics 1 Answer
Can not double jump when i fall off platform 1 Answer
Rotate camera with player 1 Answer