Help with turret behaviour

For questions about using Classic.

Post » Fri Mar 21, 2008 11:56 am

I'm wondering how to use the turret behaviour properly... at the moment I create a turret, then if the turret does not have a target, run "Add object to target" with the object in question a sprite in my game called "helicopter".

Then I have an action that's triggered by the "on shoot" event on my turret, which spawns a bullet and sets the angle towards "helicopter".

I hope that all made sense.

Anyway, the turret rotates and fires as it should when helicopters pass in range, however, it seems it always shoots at the earliest helicopter. So a helicopter can fly in range, fly out of range, another helicopter will fly into range, and the turret will rotate to face the second helicopter, but the bullet goes towards the first helicopter.

I assume this is because the helicopter is not selected in the "on shoot" event, so it just uses the first one, but how do I fix this?
B
2
S
1
G
5
Posts: 15
Reputation: 1,430

Post » Fri Mar 21, 2008 2:36 pm

'Add object to target' simply adds an object type to look for, so you only need to call it once on Start of Layout. 'Spawn object' will set the angle of the spawned object to the angle of the parent object, which is exactly what you want - you don't need to set the bullet's angle manually. 'On shoot' doesn't pick any helicopters so Construct doesn't know which helicopter you want to use. Delete the set angle action and it should all work fine.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,574

Post » Fri Mar 21, 2008 3:30 pm

Thanks for your quick response, the problem is I was hoping to make the bullets chase the target, that's why I needed to find what the turret's aiming at in the shoot event, rather than just the angle.

EDIT - actually, I suppose I could store the UID in a variable in the target acquired event, then find it again in the shoot event, is that the easiest way?

EDIT 2 - actually, I think I have the same problem in that event too... am I best off doing it manually rather than using the turret behaviour?
B
2
S
1
G
5
Posts: 15
Reputation: 1,430

Post » Fri Mar 21, 2008 3:46 pm

So, let me see if I've got this straight...

The turret fires Bullet A at Helicopter 1. The bullet is a homing bullet that chases the helicopter.

Helicopter 1 moves out of range. Helicopter 2 moves into range. The turret changes it's target to Helicopter 2.

So now you want Bullet A to change course and chase Helicopter 2? Is that correct?
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Fri Mar 21, 2008 3:52 pm

[quote="deadeye":5ormrreq]So, let me see if I've got this straight...

The turret fires Bullet A at Helicopter 1. The bullet is a homing bullet that chases the helicopter.

Helicopter 1 moves out of range. Helicopter 2 moves into range. The turret changes it's target to Helicopter 2.

So now you want Bullet A to change course and chase Helicopter 2? Is that correct?[/quote:5ormrreq]

No, sorry, I want the turret to fire at the helicopter it's currently aiming at, from the "on shoot" event. The trouble is, the specific helicopter can't be determined within the "on shoot" event, only the angle, so I can't tell the bullet which helicopter it should be chasing.
B
2
S
1
G
5
Posts: 15
Reputation: 1,430

Post » Fri Mar 21, 2008 3:52 pm

I think you've got it right up to the end, deadeye. But if I'm reading it right he wants the bullet to keep chasing the first helicopter, even when the turret isn't targetting it, but for new bullets fired not to chase it.
Because he's picking the first helicopter for the homing bullets and all bullets are globally homing on that target he can't have bullets chasing different targets.
B
3
S
2
G
4
Posts: 130
Reputation: 1,735

Post » Fri Mar 21, 2008 4:10 pm

[quote="Drew Carey":30ohvm9g]I think you've got it right up to the end, deadeye. But if I'm reading it right he wants the bullet to keep chasing the first helicopter, even when the turret isn't targetting it, but for new bullets fired not to chase it.
Because he's picking the first helicopter for the homing bullets and all bullets are globally homing on that target he can't have bullets chasing different targets.[/quote:30ohvm9g]

Yes, that's right.

If the event was "on shoot at (object)", so in my example "on shoot at helicopter", then I could make the bullet follow that helicopter, or apply actions directly to the targeted helicopter, making the turret behaviour a lot more flexible.

So my question is whether that can already be done some other way.
B
2
S
1
G
5
Posts: 15
Reputation: 1,430

Post » Fri Mar 21, 2008 4:25 pm

Well, you're right, there's no easy way to access the targeted object from the turret movement. To remedy this I've added a 'Get Target UID' expression to the turret movement for the next build. You'll be able to do something like this:

+ On shoot
: Spawn bullet
: Set bullet private variable to Gun[Turret].TargetUID

+ For each helicopter
+ Bullet's variable = helicopter.UID
: Set angle toward helicopter

Then every time a bullet is shot, it will lock on to the helicopter it was shot at, and follow it.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,574

Post » Fri Mar 21, 2008 4:34 pm

[quote="Ashley":1digixzg]Well, you're right, there's no easy way to access the targeted object from the turret movement. To remedy this I've added a 'Get Target UID' expression to the turret movement for the next build. You'll be able to do something like this:

+ On shoot
: Spawn bullet
: Set bullet private variable to Gun[Turret].TargetUID

+ For each helicopter
+ Bullet's variable = helicopter.UID
: Set angle toward helicopter

Then every time a bullet is shot, it will lock on to the helicopter it was shot at, and follow it.[/quote:1digixzg]

That's exactly what I'm after, thanks a lot! Looking forward to the next build.
B
2
S
1
G
5
Posts: 15
Reputation: 1,430

Post » Fri Mar 21, 2008 4:37 pm

Ah, I see. I've been tinkering around with it for a bit and I'm coming up with the same problem you're having. All of my homing bullets follow the first helicopter.

Maybe a new feature request for the Turret behavior? Like "Get Target UID?" Then you could do something like this, maybe:

+ Turret has target
- Turret: Spawn object Bullet
- Bullet: Set value('myTarget') to turret.TargetUID

+ Bullet: Value 'myTarget' Greater than 0
+ Group: Enemy Unique ID is bullet.Value('myTarget')
- Rotate 5 degrees toward Group: Enemy

Edit: Sweet Jesus, was I ever beaten. I've got to learn to check the thread again before hitting "submit." :oops:
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests