Homing missile

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply Page  12>
Author
1,265 Rep
Post Options Post Options   Quote jn2002dk Quote  Post ReplyReply Direct Link To This Post Topic: Homing missile
    Posted: 17 Mar 2012 at 7:37pm
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
Back to Top
16,524 Rep
Post Options Post Options   Quote newt Quote  Post ReplyReply Direct Link To This Post Posted: 17 Mar 2012 at 8:29pm
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.
Back to Top
1,265 Rep
Post Options Post Options   Quote jn2002dk Quote  Post ReplyReply Direct Link To This Post Posted: 17 Mar 2012 at 8:37pm
Originally posted by newt newt wrote:

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?



Edited by jn2002dk - 17 Mar 2012 at 8:39pm
Back to Top
11,785 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 17 Mar 2012 at 9:54pm
Back to Top
1,265 Rep
Post Options Post Options   Quote jn2002dk Quote  Post ReplyReply Direct Link To This Post Posted: 17 Mar 2012 at 10:01pm
Originally posted by Yann Yann wrote:

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

You are awesome!

That's exactly what i need

Thank you, thank you, thank you
Back to Top
4,686 Rep
Post Options Post Options   Quote zack2029 Quote  Post ReplyReply Direct Link To This Post Posted: 19 Mar 2012 at 5:39pm
Thanks Yann, great work! you're excellent.
Back to Top
19,108 Rep
Post Options Post Options   Quote sqiddster Quote  Post ReplyReply Direct Link To This Post Posted: 19 Mar 2012 at 11:08pm
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)
Back to Top
1,265 Rep
Post Options Post Options   Quote jn2002dk Quote  Post ReplyReply Direct Link To This Post Posted: 21 Mar 2012 at 10:13am
Originally posted by sqiddster sqiddster wrote:

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:)
Back to Top
1,607 Rep
Post Options Post Options   Quote fassFlash Quote  Post ReplyReply Direct Link To This Post Posted: 22 May 2013 at 3:01pm
Turret + Bullet works AWESOME for me.
Pootis
Back to Top
6,380 Rep
Post Options Post Options   Quote Nimtrix Quote  Post ReplyReply Direct Link To This Post Posted: 22 May 2013 at 4:20pm
@fassFlash:

Turret didn't exist a year ago when these posts were posted.
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down