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 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
--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))
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.
Wow, I'm glad I asked! This is nothing like anything I've
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.