2 Replies Latest reply on Oct 19, 2008 12:28 PM by Bob220867

# A characters position on a circle

I want a character to move around controlled by the user most of the time but to move in a circle when the user is not controlling it. I can get it to move around and move in a circle but the thing I’m beating my brains out on is getting the two to mix. When the character starts to move in a circle it jumps to a new position rather than starting from its current place.

So, I know where the character is and it’s rotation when the user stops controlling it but I want that position to be a point on the circle it then describes.

So I have two things I need help with:

I need to be able to work out the position of the center of the circle given that it will be at right angles to the current path of the character (the existing path is a tangent to the circle) and that I can set the radius.

Then given that basis of the circle I need to find the angular position on the circle of the character so that it can continue from there.

Here's a picture of the relationship I'm talking about

Here’s the script I’ve come to for moving the character in a circle:

on exitFrame me
x = circRadius * cos(circPos) + circCenterX
y = circRadius * sin(circPos) + circCenterY
my.loc = point(x,y)
circPos = circPos + 0.05
dx=my.locH-circCenterX
dy=my.locV-circCenterY
--find the direction of the radius
pCharacAng = atan( dy, dx)
--convert it to degrees, make it perpendicular and apply it to the character
my.rotation=integer(180+(pCharacAng * 180 / pi))
end

I’ve tried loads of different solutions but they mostly only partly work. I’m starting to get a bit gloomy about it. I tried combining different formulae from Wikipedia (and all over the place) but just can’t pin this down.

Any help with either part would be thankfully received.
• ###### 1. Re: A characters position on a circle
Here's a solution which accepts 2D points and uses vector mathematics to find the perpendicular to the tangent.

• ###### 2. Re: A characters position on a circle
Wow, I'm glad I asked! This is nothing like anything I've been attempting.

Looking at it, it seems that I need to have a variable that holds the position of the character in the previous frame to establish the tangent and becomes aPointOnTangent. Right? Otherwise it won't be able to work out direction.

I'll have a play.

Thank you.