Results 1 to 6 of 6
  1. #1
    waker3210 is offline Member
    Join Date
    Jan 2012
    Posts
    18
    Rep Power
    0

    Default Help with hitting a moving target

    I'm working on a tower defense type game and I want to know how to make the missiles look like they are actually hitting the target. What is the best way to do this?

  2. #2
    waker3210 is offline Member
    Join Date
    Jan 2012
    Posts
    18
    Rep Power
    0

    Default Re: Help with hitting a moving target

    Nevermind, i got it. Maybe not precise, but it looks pretty good to me.

  3. #3
    waker3210 is offline Member
    Join Date
    Jan 2012
    Posts
    18
    Rep Power
    0

    Default Re: Help with hitting a moving target

    So it turns out i don't have it. What i did somehow managed to work, but only in one case. So, any ideas how to do this right?

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,702
    Rep Power
    8

    Default Re: Help with hitting a moving target

    Not really sure what you're actually asking. What do you do now? Why does it not look like they're hitting the target?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    waker3210 is offline Member
    Join Date
    Jan 2012
    Posts
    18
    Rep Power
    0

    Default Re: Help with hitting a moving target

    Well, I thought I could just find the distance from the bullet to the enemy and then get the time it would take to reach it at that distance. Then aim at where the enemy is, added to the time multiplied by the enemies constant velocity. That solution was effective because it was dealing with relatively short distances, but it really isn't very accurate.

    So in mathematical terms:
    (Please note that this is not workable code)

    I used the distance formula to find the distance from the bullet to the enemy:
    d = Math.sqrt(Math.pow(enemy.x - bullet.x,2) + Math.pow(enemy.y - bullet.y,2))

    Then I find the time it takes the bullet to reach the enemy based on that distance:
    t = d/bullet.speed

    Then knowing that, the displacement of the enemy would be t*enemy.speed.

    I then add the displacement to the enemies current position to find out where to shoot.

    This is not entirely accurate, but it would be okay except that when the enemies change direction it sometimes messes up. Not really sure why, it's probably something wrong in another part of my code. But ultimately i would like to find a better solution.

  6. #6
    nonybrighto is offline Member
    Join Date
    Oct 2012
    Location
    ph
    Posts
    43
    Rep Power
    0

    Default Re: Help with hitting a moving target

    why dont you use something like direction, like if( position of object == postion of bullet) object will be destroyed.
    joy wouldnt feel so gud if it wasnt for pain

Similar Threads

  1. Hitting URL with parameters
    By rockravi in forum Networking
    Replies: 3
    Last Post: 07-29-2011, 09:44 AM
  2. Replies: 1
    Last Post: 04-01-2011, 08:48 PM
  3. JMF needed on target machines
    By fatblacktone in forum New To Java
    Replies: 1
    Last Post: 04-06-2010, 07:57 AM
  4. what code for not hitting enter?
    By tornbacchus in forum New To Java
    Replies: 4
    Last Post: 04-11-2009, 04:59 AM
  5. excludes in javac target
    By ziggy in forum New To Java
    Replies: 2
    Last Post: 11-25-2008, 04:29 AM

Posting Permissions

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