Help with Weapon tracking System with Next target option

For questions about using Classic.

Post » Fri Jun 05, 2009 6:34 pm

I am making a space shootem up game and I would like to have a computer weapon tracking system with the option to go to next target.

I have the basic system down.

[code:1jzj1zhd]For Each Enemy
PlayerShip: Pick closest to: Enemy.X , Enemy.Y
AND PlayerShip Has LOS to Enemy

System: Create object
Redcross on layer 2
at (0,0) from Enemys
image point 1

PhaserFire: Set angle towards
RedCross[/code:1jzj1zhd]

But I am not sure how to on a key press to pick another target. What would be the best way to do this?
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Fri Jun 05, 2009 10:48 pm

i guess you should put the LOS-condition before the Pick Closest-condition, otherwise you might pick nothing.

for next target: you could tag the currently targetet enemy in some way (e.g. set a private variable 'isTarget'); that way you don't have to constantly run the targetting procedure, but can simply pick him. for next/prev target, you probably want a mechanism to pick the next enemy clockwise/counterclockwise to the target (with the player as center). there are two things that will help you: the AngleDiff( a, b ) expression and the 'Is Angle Clockwise to...' condition. you will probably need to put the enemy object into two different families, too, which is a workaround sometimes needed for picking 2 objects of the same object type. this sounds confusing, so here's an example:

let's say the currently targetet enemy has a pv called 'isTarget' that is set to one. let's also say that the enemy object is member to the families 'RED' and 'BLUE'.
[code:13yd4b4x]
- pick 'Red' where 'isTarget' = 1
- pick 'Blue' where 'isTarget' = 0
- For each 'Blue' (ordered) by
AngleDiff( Angle( player.X, player.Y, Red.X, Red.Y),
Angle( player.X, player.Y, Blue.X, Blue.Y)) (ascending)
- Is Angle Clockwise?
( Angle( player.X, player.Y, Red.X, Red.Y)) to
(Angle( player.X, player.Y, Blue.X, Blue.Y))
- Is Red('isTarget') Equal To 1?
-> this is your man!
-> Set Value Blue('isTarget') 1
-> Set Value Red('isTarget') 0
[/code:13yd4b4x]as you can see, we need the two families to pick the correct enemy objects without loosing track of the current target.

[size=50:13yd4b4x]i hope this works[/size:13yd4b4x]
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Sat Jun 06, 2009 12:26 am

that's a pretty clever little technique there dkdoom
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sat Jun 06, 2009 2:51 am

Thanks dkdoom for your help with this. I tried out your code.
in the cap below.

[url:3b4un9p5]http://dl.getdropbox.com/u/1244375/SpaceShipDemo6.cap[/url:3b4un9p5]

I am still having trouble with it. It seems to loop between just two targets. So if you or anyone else can take a look at to see whats wrong


edit

I forgot to to put down the controls.
arrow keys to move
space key to fire
C key to start tracking.
X and V keys to target next ship

.
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Sun Jun 07, 2009 3:12 am

Ok I have rethought the tracking System and came up with new system using an array.

[url:38rw60wl]http://dl.getdropbox.com/u/1244375/SpaceShipDemo6B.cap[/url:38rw60wl]

But now I have run into a new problem. When the games starts with the 4 big Rocks it is working fine. But once you blow up one of the big rocks it makes three little rocks. And the system breaks down.

My TotalTargets Var shows only 3 when it should show 6.
The array is showing all 6 targets. But for some reson the little rocks are not getting added to the total targets var. Both the big rocks and the little rocks are in the same Eneny family. I am using Enemy.Count to get TotalTargets.

Controls.
arrow keys to move
space key to fire
C key to start tracking.
X and V keys to target next ship
B
15
S
10
G
8
Posts: 107
Reputation: 4,944

Post » Sun Jun 07, 2009 12:56 pm

thanks, lucid :)

maxum, i had a look at your first try, but didn't find the bug ... so i rebuild it, but got the same result :P. i believe there is either a logical error in my thinking, or the For-Each-condition does not sort the AngleDiff(Angle(),Angle())-expression correctly; in any case, it works when using private variables for sorting: download cap
B
2
S
2
G
4
Posts: 171
Reputation: 1,792

Post » Mon Jun 08, 2009 10:57 pm

Thanks again dkdoom for your help with this :D

[url:221rlrmf]http://dl.getdropbox.com/u/1244375/SpaceShipDemo7.cap[/url:221rlrmf]

It is working well until you blow up one of the enemy. Then you start to run in to problems. I have to find the right spot to repick the target so it keeps runing right after you kill the target that has a lockon.
B
15
S
10
G
8
Posts: 107
Reputation: 4,944


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest