Pathfinding to a sprite depending on Instance variable

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I would like a sprite - with the Pathfinding Behavior - to Find Path to one object out of several depending on an instance variable.

    For example, the sprite has instance variable = 2. There are three sprites named "target1", "target2" and "target3". I CAN make it work with three different events with conditions that compare the variable, but I would like this to work out with ONE single Event.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is where you use a Family, put all 3 objects into a Family and put the instance variable as a Family instance variable. Then you can say if Family.var=2 find path to Family.

  • There are three sprites named "target1", "target2" and "target3"

    Do they need to be different objects? Consider combining them into one sprite, maybe with different animations.

    If you are sure they should be different objects, then you need to add them all to a family and define the variable on the family. Then you will be able to pick any family instance:

    Family variable=2 -> Sprite find path to Family

  • OK, I changed it so that there is only one target sprites with the instance variable "tar". I call it "target" There are three representations of it, and the instance variable is set to 1, 2 and three for them respectively. The sprite that moves with the Pathfinding Behavior has the variable "var" set to 3. I call it "walker'.

    Then I have these two Events:

    ---

    1:

    System Every 0.3 seconds walker find target to (target.x, target.y)

    walker var=target.tar

    2:

    walker On Pathfinding path found walker Move along path

    ---

    Then nothing happens, so it somehow does not work.

    If, however, I disable or delete the second condition at the first event (walker var=target.tar) so that the instance variables are not used, then it works and "walker" goes for the first one of the targets (because it was created first).

  • You need to pick a target instance first. When you use "find path to target" without picking, then it will always use the first instance.

    "walker var=target.tar" condition is also incorrect, it will not pick target instance.

    Try this:

    System Every 0.3 seconds
    target Compare variable tar = walker.var 
    .... walker find target to (target.x, target.y)
    

    It needs to be a single event with two conditions.

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