Quick and Dirty Heat Seeking Missiles...

BarkBarkCoBarkBarkCo Member Posts: 1,400
edited November -1 in Introductions
Here is a game I'm messing with that is in the very early stages...

I liked the result of the heat seeking missiles logic I added so much, I thought I'd share the joy!

http://gamesalad.com/game/play/56585

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    Can't see it at work, but looking forward to trying it out tonight :D

    Heat seekers are my favourite weapons of choice :P

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Likewise QS, defo looking forward to trying it out ... damn windows at work!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Nice demo!! I will have to check out how you did that!
  • quantumsheepquantumsheep Member Posts: 8,188
    firemaplegames said:
    Nice demo!! I will have to check out how you did that!

    It's as if he enjoys torturing us!

    ;)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • beefy_clyrobeefy_clyro Member Posts: 5,394
    yeh right. talk about rubbing it in! is it half 5 yet?
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    @firemaplegames, Thanks for the kind words!

    It's real simple ... and kinda dirty.

    There is no live tracking of the falling bombs. They are set to fall at a random x position, at set intervals. About .5 seconds into there existence, I mark their current X position in a game (real) attrib, `game.LastBombX`. Then, when missiles are spawned, I have them interpolate their own x position over a 1~ second period to `game.LastBombX`. That is what makes them look like they are "thinking" ...

    I'm in the theoretical stages on a method that will allow me to always track the bomb with the lowest `self.position.y` ... but that is yet to be added.
  • quantumsheepquantumsheep Member Posts: 8,188
    Ooh! Sounds interesting!

    I've also used interpolate to make 'Enemy' homing missiles that track the player.

    In your method, are you changing the last bomb value to the individual bombs position? So if two bombs spawned, for .5 seconds bomb1 would have the value 'last bomb' until bomb 2 spawned and it would switch to that?

    BAH! Won't get home for another 2 hours or so and I'm gagging to see how this works...

    QS :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Only one bomb is spawned at a time, in .5 second intervals (I think..I'm also on a PC right now). I'm only logging the x position of a bomb, .5 seconds into its life cycle; under the assumption that the bomb and missile will intersect in flight. Each new bomb overwrites the logged x position, so only one bomb is tracked at a time. That allows for some misses that I hope to clear up soon with logic that only tracks the bomb that has fallen the most in the scene.

    That said, if you fire at a rate greater than 1 missile per .5 seconds, at least one missile would track every bomb.
  • EastboundEastbound Member, BASIC Posts: 1,074
    Oh wow I had always marked heatseaking for the player off because I thought it was too complicated without really thinking about it.

    Thanks for the epiphany!

    Yeah you could simply have every enemy check if their position x and y are closer to the player's than the global variables for closest_e_x and closest_e_y and change closest_e_x and y if they are.

    I'm afraid this would be a little too heavy for an iPhone shooter (every enemy would have to check and perhaps change variables with every tick of the game's clock), but I think it would work fine on iPad, and maybe even the newer phones (never tested on 3Gs).
  • jmp909jmp909 Member Posts: 73
    hi,

    not looked at your example yet (no mac here) but I found this really nice heat seeking flash example (with source), with modifiable parameters for turn speed etc.

    i've pasted the main function below....if you altered it to use game variables eg followerMoveX, targetX etc should be adaptable with constrains. (note vectorToAngle = atan2)

    http://www.freeactionscript.com/2008/12/game-weapons-heat-seeking-missiles-rockets-torpedoes/

    `

    function doFollow(follower, target):Void

    {

    //get distance between follower and target

    follower.distanceX = target._x - follower._x;

    follower.distanceY = target._y - follower._y;

    //get total distance as one number

    follower.distanceTotal = Math.sqrt(follower.distanceX * follower.distanceX + follower.distanceY * follower.distanceY);

    //calculate how much to move

    follower.moveDistanceX = turnRate * follower.distanceX / follower.distanceTotal;

    follower.moveDistanceY = turnRate * follower.distanceY / follower.distanceTotal;

    //increase current speed

    follower.moveX += follower.moveDistanceX;

    follower.moveY += follower.moveDistanceY;

    //get total move distance

    follower.totalmove = Math.sqrt(follower.moveX * follower.moveX + follower.moveY * follower.moveY);

    //apply easing

    follower.moveX = missileSpeed*follower.moveX/follower.totalmove;

    follower.moveY = missileSpeed*follower.moveY/follower.totalmove;

    //move follower

    follower._x += follower.moveX;

    follower._y += follower.moveY;

    //rotate follower toward target

    follower._rotation = 180 * Math.atan2(follower.moveY, follower.moveX)/Math.PI;

    }

    `

  • jmp909jmp909 Member Posts: 73
    i have posted this here
    http://gamesalad.com/forums/topic.php?id=7197#post-47531

    but have issues.
Sign In or Register to comment.