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

QuestionManQuestionMan Member Posts: 81
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 Member, Sous Chef, PRO Posts: 2,881
    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 Member Posts: 81
    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 Member, Sous Chef, PRO Posts: 2,881
    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 Member Posts: 81
    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 Member, Sous Chef, PRO Posts: 2,881
    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!
Sign In or Register to comment.