Java Sprites, Missile Homing
Author |
Message |
ImFluix
|
Posted: Fri Jun 15, 2012 6:07 pm Post subject: Java Sprites, Missile Homing |
|
|
I'm creating a 2D platform game for a summative in class. In one of the level there are missiles which lock onto you and and chase you.
What i'm trying to do is have the playable character move around the level and collect some resources before the missiles hit you.
I am looking on the web for a good pathfinder for this situation, but that's not the problem. The problem is that I want the missiles to move in a curved way
like how missiles usually do.
Something similar to this - http://www.youtube.com/watch?v=H9DCyM_dvPQ
It would be appreciated if someone could direct me on how to approach this. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonWasp
|
Posted: Sun Jun 17, 2012 5:23 pm Post subject: RE:Java Sprites, Missile Homing |
|
|
Give the missile a position, direction (an angle) and a speed.
On every update, determine the angle to the target (player) and "move" the angle of the missile towards that angle. Remember that 360 = 0, and to get from 355 degrees to 15 degrees, you should turn towards 360 = 0 degrees, not towards 15 degrees directly. You may have to write several if statements to match all cases.
After updating the angle, use the speed and the angle to find a velocity (speed in directions x, y) and move the missile that amount.
Draw the missile based on its angle (NOT angle to target) and position. |
|
|
|
|
|
|
|