Homing missile

Get help using Construct 2

Post » Sat Mar 17, 2012 7:37 pm

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
B
13
S
2
G
1
Posts: 85
Reputation: 1,502

Post » Sat Mar 17, 2012 8:29 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Mar 17, 2012 8:37 pm

[QUOTE=newt] 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.[/QUOTE]
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?

jn2002dk2012-03-17 20:39:59
B
13
S
2
G
1
Posts: 85
Reputation: 1,502

Post » Sat Mar 17, 2012 9:54 pm

Last edited by Yann on Sun Sep 14, 2014 11:17 am, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Mar 17, 2012 10:01 pm

[QUOTE=Yann] http://dl.dropbox.com/u/23551572/C2/homingMissiles.capx[/QUOTE]
You are awesome!

That's exactly what i need

Thank you, thank you, thank you
B
13
S
2
G
1
Posts: 85
Reputation: 1,502

Post » Mon Mar 19, 2012 5:39 pm

Thanks Yann, great work! you're excellent.
B
33
S
5
G
4
Posts: 7
Reputation: 7,743

Post » Mon Mar 19, 2012 11:08 pm

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)
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Wed Mar 21, 2012 10:13 am

[QUOTE=sqiddster] 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)[/QUOTE]
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:)
B
13
S
2
G
1
Posts: 85
Reputation: 1,502

Post » Wed May 22, 2013 3:01 pm

Turret + Bullet works AWESOME for me.
HARMLESS SIGNATURE THAT IS VIEWED BY OTHERS AS OFFENSIVE AND CONTROVERSIAL
B
14
S
3
G
3
Posts: 356
Reputation: 4,362

Post » Wed May 22, 2013 4:20 pm

@fassFlash:

Turret didn't exist a year ago when these posts were posted.
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Next

Return to How do I....?

Who is online

Users browsing this forum: Artpunk and 19 guests