Help with Weapon tracking System with Next target option

This forum is currently in read-only mode.
  • 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.

    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 Enemy�s
                                             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?
  • 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'.

    [ul]	[li]pick 'Red' where 'isTarget' = 1[/li]
    [/ul]    - 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.
    
    [h2]i hope this works[/h2]
  • that's a pretty clever little technique there dkdoom

  • Thanks dkdoom for your help with this. I tried out your code.

    in the cap below.

    http://dl.getdropbox.com/u/1244375/SpaceShipDemo6.cap

    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

    .

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

    http://dl.getdropbox.com/u/1244375/SpaceShipDemo6B.cap

    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

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks again dkdoom for your help with this

    http://dl.getdropbox.com/u/1244375/SpaceShipDemo7.cap

    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.

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