Rotation Calculation Question

FallacyStudiosFallacyStudios Member Posts: 970
edited September 2012 in Working with GS (Mac)
Hey all,

So if anyone is good with the formulas for calculations I could use some help. I have a large Swinging Axe actor that is on my platformer that continually rotates counter clockwise.

I'd like to be able to calculate whether my hero actor is touching either end where the axes are located. Now I'm positive this is doable. It would obviously be in a rule that gives a range compared to the Hero actors pos x. I'm just uncertain as to which formulas to use to calculate off of the current rotation of the axe to where the 2 axes are located on either side (it is all 1 image/actor).

Lets say my axe wasn't rotating I could easily make a range that says if my Hero actors pos x <= self(axe).pos.x+50 AND hero pos x >= self(axe).pos-50 AND Axe collides with Hero actor (more specifically if I added a range for the Y's it would also figure if out if I'm touching the right area of the axe). Those rules would give me what I am looking for without it rotating. So now I just need to figure out where those locations are when it is in the middle of rotating if you get what I mean.

Anyways thanks and sorry if I confused anyone. Let me know if you need clarification.

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    edited September 2012
    @FallacyStudios -- I think the formula you want would involve the magnitude function (to determine the distance from the center of the double headed axe).

    Make three real (game level) attributes. How about calling them axeX, axeY, and axeWidth

    In the double headed axe actor give these game level attributes their working values:
    axeX -> self.position.X
    axeY -> self.position.Y
    axeWidth -> self.width

    In the hero actor you would create an attribute called distanceFromAxeCenter;
    Constrain Attribute: (self.distanceFromAxeCenter) To: (magnitude(game.axeX-self.Position.X,game.axeY-self.Position.Y))

    Then have a rule in the Hero;
    When (all conditions are valid):
    Attribute (self.distanceFromAxeCenter) < (game.axeWidth/2)
    Actor receives event (overlaps or collides) with (actor of type) (DoubleAxe)
    -- do your thing
    otherwise
    -- do your other thing

    That should get you close to what you want.....
  • FallacyStudiosFallacyStudios Member Posts: 970
    @RThurman That does sound like what I am looking for. Thanks alot :). I'll give it a shot.
  • FallacyStudiosFallacyStudios Member Posts: 970
    @RThurman Perfect man, you are awesome. The only slight modifications I had to make was I switched it to axeHeight rather than Width cause the Height was the long part with the 2 axe heads. And I had to set it to > rather than < because it was triggering me being hit if I touched the middle rather than the axes. Lastly I changed it to axeHeight/4 just because I wanted it closer to the axe heads rather than any of the pole.

    Thanks again you rock.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Glad its working for you. GameSalad is pretty awesome!
Sign In or Register to comment.