Character follows a circular rotation around centre with distance, but loops with 360 turn and can't figure out how to move to a certin point
To set the scene I have my player rotating around a centre pivot. You swipe on the mobile device and it will shoot a raycast to hit the object. The player will then move along a cylinder shape towards that position. So imagine the platform the player moves on is a cylinder. The character moves up and down on the Y axis and rotates around the cylinder.
Enemy's spawn on this cylinder with a 0 - 360 placement on it. The player moves on the cylinder from positions 0 to - infinity or + infinity. I sorted it out so the players rotation resets to 0 after it passes 360, same if it passed 0 to 360. Makes it easier to read the position of the player.
The bit I can't wrap my head around is how I can tell if the enemy hit is to the left or the right..
It is easy enough to say if the value is lower than what the current position of the player is then move on the - rotation, same if it positive on the + position. This works fine if it is between 360 to 0 but not if its crossing over from 355 to 5, it should only be 10 degrees away, not 350.
EXAMPLE
The player is on +2 and the enemy is on +355, if I swipe to the left it will go all the way around the cylinder to the right. If i script it so it moves the other way. The same issue will happen if the player is on +355 and the enemy is on +2, it will go the long way around.
The script I am using to move the character around is:
//Updates variable position
rot -= .1f * Time.deltaTime;
//sets and updates the character position
transform.position = origin + Quaternion.Euler(0, rot, 0) * new Vector3(0, 0, distance);
I hope I have worded that well enough for you to understand...
I added a really bad picture to help with setting the scene. :)
Your answer
Follow this Question
Related Questions
How to find a position's angle around an arbitrary axis? 1 Answer
How to properly make an object follow the edge of another object? 0 Answers
Can you help me make an algorithm out of these parameters? 1 Answer
Advanced placing position from the same angle of target position 0 Answers
Object with fixed position but follows camera rotation 0 Answers