A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Finding the end of a moving sprite

  1. #1
    Member
    Join Date
    Dec 2007
    Posts
    85

    Finding the end of a moving sprite

    I'm currently building a cannon launching game, where the player adjusts a cannon's angle in order to help fire it. What I need to be able to do is find where the end of this cannon is, such that I can start firing a cannon shell from that point.

    I ran some initial testing, and trying to use x and y coordinates doesn't work. They'll only track the original positions, not the new ones. Trying to use rotations to find the point didn't help either.

    The cannon is angled using rotation, within a range of 0 to 15 degrees. In addition, the cannon movieclip is composed of three areas. These areas are named "cannon_load", "cannon_launch", and "cannon_barrel". The third area is the one where I need to find the far end of.

    Any ideas?

  2. #2
    Senior Member
    Join Date
    Oct 2007
    Location
    Leeds, UK
    Posts
    118
    If you know:

    * the x,y coordinates of the other end of the cannon (the end that the shells DON'T come out of) (call that point (baseX,baseY) )

    * the length of the cannon (call it L)

    * the angle between the cannon and the horizontal (call it A)

    then trigonometry tells you that the far end of the cannon is the point

    (baseX + L*Math.cos(A*Math.PI/180), baseY + L*Math.sin(A*Math.PI/180) )

  3. #3
    Member
    Join Date
    Dec 2007
    Posts
    85
    Wow, I never thought I'd see an applicable use for such advanced math.

    Anyway, I ran that formula, using the cannon's registration point as the base, since this was the only point of the cannon that would never change. It worked perfectly. Thanks very much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center