Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Interpolate Rotation value - how do i stop the actor rotating the 'wrong' way?

EwokPDEwokPD Posts: 35Member, PRO
edited September 2012 in Working with GS (Mac)

I have an actor that i want to point where it is shooting - imagine a triangle facing upwards with bullets coming out of the top part of the triangle... and three targets above it... one off centre to the left... one straight up and one to the right.

I am using vector to angle based off start XY coords for the triangle actor... and end XY coord for the target clicked.

I am then interpolating the triangles self.rotation to the angle i have generated above (+or- a correction factor needed to align the triangle properly) - eventually each of the three corners of the triangle will be able to target independently so each corner of the triangle with have a different correction factor.

Now this almost works - for two of the actors the triangle will rotate the shortest distance and target the target properly... for the other target the triangle spins the wrong way when interpolating to the target so takes the longer route which looks silly and need fixing. I am guessing the triangle is choosing to rotate the 'wrong' way due to the maths getting confused when the angle goes from 359 back to 0 - but am not sure how to fix it - can anyone offer any ideas please.

Should i have not explained myself properly please let me know and will upload some graphics to aid in the description.


  • RThurmanRThurman Posts: 2,827Member, Sous Chef, PRO
    The general formula would go something like:

    For example, to get an arrow actor to point at the mouse you could use the following equation in an interpolate behavior:

    self.Rotation +(((vectorToAngle(game.Mouse.Position.X-self.Position.X, game.Mouse.Position.Y-self.Position.Y)-self.Rotation )+180)%360)-180
  • EwokPDEwokPD Posts: 35Member, PRO
    Thanks RT -i will give that a go now
  • EwokPDEwokPD Posts: 35Member, PRO
    That works like a charm...very much appreciated... it was frying my brain that problem! :P
  • RThurmanRThurman Posts: 2,827Member, Sous Chef, PRO
    Glad its working for you!
  • tenrdrmertenrdrmer Posts: 9,934Member, Sous Chef, Senior Sous-Chef
    Very Nice @RThurman you have pretty well become our math guru these days.

    It's not my fault I never learned to take responsibility for anything. ;)

  • RThurmanRThurman Posts: 2,827Member, Sous Chef, PRO
    edited October 2012
    @tenrdrmer & @uptimistik -- thanks guys! That kinda makes my day!

    Actually, my very first post on this forum was about this exact same issue:

    And 731 posts later -- its still my most fun discovery.

    The thing I really like about GameSalad is that it is so easy to use and to experiment with. GameSalad makes it easy to think about the math because it makes all the other development stuff so freakin easy! And the built in functions make the math relatively easy too.
This discussion has been closed.