Homing missile

0 favourites
  • Hello

    I am in the process of porting my game from Game Maker to C2 and all has been smooth so far except for this issue

    I need the player to shoot an object which will lock on to the nearest enemy of a specific type and then move towards it until they collide

    So basically i need to

    1. Find the nearest enemy

    2. Make sure the missile follows it

    3. Make the missile continue in a straight line if that enemy is destroyed before it hits its target

    Apologies if this is already covered somewhere but i looked through the FAQ and did a search in this section but didn't find anything i could use

    Any help will be much appreciated

  • If you are using the bullet behavior, or move at angle.

    1: Bullet pick closest target

    2: Bullet set angle towards target

    3: Wont matter if 1 and 2 are continuous.

  • If you are using the bullet behavior, or move at angle.

    1: Bullet pick closest target

    2: Bullet set angle towards target

    3: Wont matter if 1 and 2 are continuous.

    Thank you for your reply

    I don't understand

    I am using bullet behaviour but i don't see anything about pick closest target in it's behaviour

    I am hopeless at trigonometry so i was hoping i could do this some other way. Like in Game Maker there is a move towards behaviour you put in the every tick event

    What am i missing?

    <img src="smileys/smiley1.gif" border="0" align="middle" />

  • http://dl.dropbox.com/u/23551572/C2/homingMissiles.capx

    You are awesome!

    That's exactly what i need

    Thank you, thank you, thank you <img src="smileys/smiley4.gif" border="0" align="middle">

  • Thanks Yann, great work! you're excellent.

  • If you want the missiles to behave a bit more realistically, I would suggest, instead of setting the angle straight towards the object, every tick set the angle to: anglelerp(rocket.angle,angle(rocket.x,rocket.y,target.x,target.y),dt*somespeedfactor)

  • If you want the missiles to behave a bit more realistically, I would suggest, instead of setting the angle straight towards the object, every tick set the angle to: anglelerp(rocket.angle,angle(rocket.x,rocket.y,target.x,target.y),dt*somespeedfactor)

    Will try this

    I can't claim to have a firm grasp of what lerp does exactly but it can't hurt to try. Thank you:)

  • Turret + Bullet works AWESOME for me.

  • fassFlash:

    Turret didn't exist a year ago when these posts were posted. <img src="smileys/smiley2.gif" border="0" align="middle" />

  • Anyways, the message quite clear no matter when. Pathfinding can go screw itself.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • > If you want the missiles to behave a bit more realistically, I would suggest, instead of setting the angle straight towards the object, every tick set the angle to: anglelerp(rocket.angle,angle(rocket.x,rocket.y,target.x,target.y),dt*somespeedfactor)

    Will try this

    I can't claim to have a firm grasp of what lerp does exactly but it can't hurt to try. Thank you:)

    nice work....but i dont understand what anglelerp means.sorry for the inconvenience

  • planetheads:

    If you check out the "[How do I] FAQ" thread by Kyatric there are some links to threads where lerp (linear interpolation) is explained in detail. Anglelerp is pretty much the same only it's meant for angles.

    Unlike the standard lerp, this takes in to account the cyclical nature of angles.edited><editID>Nimtrix</editID><editDate>2013-06-18 14:30:22</editDate></edited>

  • Couldn't you justt use rotate towards object? :P

  • EncryptedCow

    You could, but it wouldn't be smoothed like the lerp would. Depends on what you want really.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)