GameSalad

Howdy, Stranger!

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

I want to fire a cannon object with the mouse using a vertical line behind it, probs with vect2angle

QuestionManQuestionMan Posts: 81Member
edited August 2012 in Working with GS (Mac)
How would I set up the formula to have my mouse fire my cannon from behind the cannon (not in front)?

Answers

  • RThurmanRThurman Posts: 2,832Member, Sous Chef, PRO
    Its not a complete answer, but for starters you can replace the "Rotate to Position" behavior (in the cannon actor) with a "Rotate to Angle" behavior. The formula for the angle would be:
    vectorToAngle( self.Position.X - game.Mouse.Position.X , self.Position.Y - game.Mouse.Position.Y )

  • QuestionManQuestionMan Posts: 81Member
    Ya RThurman I've been doing that for now(works in front but not in back) but I obviously need some tricky math to do it properly.
  • RThurmanRThurman Posts: 2,832Member, Sous Chef, PRO

    Ya RThurman I've been doing that for now(works in front but not in back) but I obviously need some tricky math to do it properly.

    @QuestionMan
    The trick is to reverse the subtractions. Instead of:
    vectorToAngle( game.Mouse.Position.X - self.Position.X , game.Mouse.Position.Y - self.Position.Y )
    you would use:
    vectorToAngle( self.Position.X - game.Mouse.Position.X , self.Position.Y - game.Mouse.Position.Y )
  • QuestionManQuestionMan Posts: 81Member
    perhaps, except theres more to it than that because the placement of the mouse/finger is to the far left of the image, so angles have to be involved
  • RThurmanRThurman Posts: 2,832Member, Sous Chef, PRO
    Perhaps.... but don't you think its at least worth trying before you succumb to the lure of "tricky math".

    It will take less than a minute to modify and test the cannon template. Try it! You might like it!
This discussion has been closed.