Compare variables of X Objects within Line of Sight?

0 favourites
  • 10 posts
From the Asset Store
solution for games like "fruit ninja" and drawing applications
  • I have a Family that has rules.

    The Family roams around freely and they select goals depending on instance variables.

    I am using Line of Sight and don't have much experience with it.

    If one NPC sees two or more enemies at once. (like a herd).

    How do I have it select the lower level or the weakest one?

    I know I would use conditions to compare variables, but I am not sure how to check the variable of the objects within the Line of Sight.

    Is there an option for that and I am just missing it?

  • Im not sure that its optimised for multiple detections at the same time, but if it can you would need to use something like pick by comparison or evaluate.

  • I'm not sure how I didn't know about those.

    I will have to read up on those.

    I'm not fully ready to implement it just yet.

    If it doesn't work I will be back at a later time, but it seems like it would work.

    I didn't expect a reply so fast.

    Thank you.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • https://www.scirra.com/manual/124/system-conditions

    I looked at it and I still have the same issue.

    I am not knowing how to look for the lowest variable value from the family objects.

    Do this:

    Compare

    6,7,3,8

    Select 3.

    Not This

    Check for 1.

    6,7,3,8

    Check for 2.

    6,7,3,8

    Check for 3.

    6,7,3,8

    Select 3.

    To get the value I need, I have to divide two variables.

    The max hp the objects has/ the current amount of hp.

    200/100 is 0.5

    The results range from 0.0001 to 1000.

    I would like this to only have to calculate when an object is targeted.

    Having it calculate every X seconds causes a lot of useless calculations.

    I think the only way to do this without setting up to many variables is by using an Array.

    I can use the objects UID to track in an Array and do the math required as needed.

    This will only return one value at a time, but I can set that value to a single instance variable.

    This is better than creating X amount of variables in case X amount of objects are in Line of Sight.

    I am hoping there is a more simple solution then this.

    The question still remains, how do I select the lowest variable without checking every single possible value.

  • I actually came up with a solution.

    I would have to make a new instance variable for selected targets UID and two for target values.

    When a target enters the Line of Sight of the targeting object it will calculate what is needed and set the targets UID and current targets value to the instance variables.

    If there is another target it will Calculate that as well.

    If the new calculated target value is lower than the current one then it will be replaced and the UID will be replaced as well.

    If the targeting object looses the target or the the target is destroyed then the three variables will be reset.

    I'm still hoping for a more simple solution though...

  • Probally the same as you did allready.

    https://www.dropbox.com/s/fclzlu1looy70 ... .capx?dl=0

  • I only have 1 family. The objects in the family goes after other objects in the same family. Will that cause any issues? I don't think it would but am not 100% sure.

    Should I have 2 duplicate families?

    Yours is actually cleaner. Mine was a mess from trying to figure it out.

    Thanks for taking the time and helping.

  • Yuck, they eat each other. Yes, i think you need 2 family's with the same items as members.

    Not that i tested that, but it should work the same as this version:

    https://www.dropbox.com/s/mr26jocqkvdop ... .capx?dl=0

  • I see you marked out the Else statement. I had trouble figuring out why the Line of Sight range was being ignored. I marked it out on the first example.

    I feel I have to explain a small bit. It is more of an hierarchy. Higher rank will go after lower rank. It is similar to a food chain.

    Thanks again. I think 2 families would make more sense. I don't really see a problem with only using 1 though, but am not 100% sure. If anything it will be easier to work with, calling two things by one thing when they are two things can get confusing.

  • The else was just to (in this example) keep them eating, even when there is no food in sight.

    I think you going to have troubles with picking a UID starting from previous pickings coming from an overlap between 2 familys. Thats why i anticipated with a distance check version. And yes, only 1 family wil (i think) not work at all.

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