Set parent

0 favourites
  • 5 posts
From the Asset Store
A whole set you need to create a gorgeous winter 2d game
  • I'd like to do something like this:

    There's many soldiers on the map. They all moves randomly. All of them has its own crosshair (aim). If soldier sees another soldier in his crosshair he shoots.

    There's my pseudo-code for this:

    <font size="2">events:

    • Start of level
    • for every soldier

    Action:

    • create crosshair
    • pin crosshair to soldier

    event:

    • crosshair collides with soldier

    action:

    • soldier fire

    </font>

    But wrong soldier is firing (not shooter-soldier but target-soldier is shooting).

    I think it should be done like this:

    <font size="2">events:

    • Start of level
    • for every soldier

    Action:

    • create crosshair
    • pin crosshair to soldier
    • for that crosshair set this soldier as parent

    event:

    • crosshair collides with soldier

    action:

    • parent soldier fire

    </font>

    Is there any action similar to parenting?

  • Im not quite sure what you are trying to explain, Please provide your capx, it gives us more of a chance to help you.

    Are your soldiers separate sprites or just different instances of one?

    You might have to assign a separate id to each soldier, in the sprites properties panel,

    Try explain the game more,

    Are you setting a cursor to the mouses position, and if the cursor collided with a soldier you want it to fire?

  • I think I understand what you want to do.

    You want basically pick the soldier that possess the crosshair

    You can do that quite simply like that :

    create two instance variable for the crosshair object:

    • soldierUID type number default 0
    • firing type bolean default false
    Global variable crossDist = 100  // Distance between soldier and crosshair
    System: On start of layout
       -> destroy crosshair
       System: Foreach Soldier
          -> System: create crosshair on layer 0 at cos(soldier.angle)*crossDist,sin(sodlier.angle)*crossDist
          -> crosshair: pin to Soldier
          -> crosshair: set sodlierUID to Soldier.UID
    System: Every tick
       -> crosshair: set firing to false
    crosshair: is overlapping Soldier
       -> crosshair: set firing to true
    crosshair: is firing
    soldier: pick instance with UID crosshair.soldierUID
          -> Sodlier: spawn Bullet
          -> Bullet: set angle to Soldier.angle
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Be sure also to read (again) how events work this could help you clean out your code.

  • Yann, thanks. It works perfectly.

    Kyatric, I sure will.

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