Rotation Help

This forum is currently in read-only mode.
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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?

    http://www.louisferina.com/games/rotationHelp.cap

    Thanks

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

    <img src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Vector_by_Zureks.svg/300px-Vector_by_Zureks.svg.png">

    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

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)