Rotation Help

For questions about using Classic.

Post » Sat Jan 31, 2009 7:32 pm

I'm trying to make a turret like object with 3 parts to it. The top part rotates exactly to where it should be facing. The middle should be half the angle of the top and bottom. The bottom rotates slowly. The problem occurs when the bottom part crosses the 360 and 0 angles. The equation doesn't work anymore: middle.Angle=(top.Angle+bottom.Angle)*0.5 I need this equation to work because the bottom part may be rotating to other angles in my game and not just stopping when it meets the top angle.

Any ideas?

[url:1hxoy77c]http://www.louisferina.com/games/rotationHelp.cap[/url:1hxoy77c]

Thanks
B
77
S
49
G
25
Posts: 346
Reputation: 17,409

Post » Sat Jan 31, 2009 8:41 pm

this looks like a job for vectors!!!!!!!!! (math vectors)

they allow you to get angles for stuff like this, and weight each angles influence on the overall outcome.



youll have to set the middle parts angle to the angle from the initial point to the sense of a vector which is the average of the vectors of your top part and bottom part.
so first youd get the sense of your top and bottom like this (handle the vectors x and y seperately)

for the top vectors x youd make it:

cos(top.angle)*10 (this is the sense for x)
sin(top.angle)*10 (this is the sense for y)

and youd get the sense of the bottom in the same way

then to get the x and y of you middle sense youd do this

(((cos(top.angle)*10 )+(cos(bottom.angle)*10 ))/2)
(((sin(top.angle)*10 )+(sin(bottom.angle)*10 ))/2)

to find the middles angle youd do this
angle(0,0,(((cos(top.angle)*10 )+(cos(bottom.angle)*10 ))/2),(((sin(top.angle)*10 )+(sin(bottom.angle)*10 ))/2)) and that should give you the proper angle.

you can just paste this in and it should work

angle(0,0,(((cos(top.angle)*10 )+(cos(bottom.angle)*10 ))/2),(((sin(top.angle)*10 )+(sin(bottom.angle)*10 ))/2))

when the angle difference between your top and bottom is greater than 180, the middle will seem to flip, like it already did in the original i have no idea how to stop this atm.

but the crossover problem is now fixed
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

Post » Sat Jan 31, 2009 9:15 pm

Hey thanks for the help and the explanation, that helped me to understand what was going on. It worked except for the flipping at 180, like you said, but it's a much smoother result.
B
77
S
49
G
25
Posts: 346
Reputation: 17,409


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests