How do I

0 favourites
  • 14 posts
  • hi there this might sound really simple and im being dumb about it. but im making a game which has simulated battles and trying to do an event where every tick friendly troops find a path to nearest enemy which ive put into a family. and vice versa for the enemy but i cant work out how to do this.

    there can be up to 100 friendly troops and enemy troops so its alot of sprites which i need each of them to find thier own mark to march towards.

    also something else i havent tryed to work out yet but would be good if answered is how to i get a minion once they start marching towrads enemy stop a set amount of space off them instead of on top of them.

  • "----live without you?

    I want to know,

    How do I breathe without you?

    If you ever go..."

    In all seriousness though, you can't make them find paths EVERY TICK because they only start moving after the "ON PATH FOUND" event. Even with 6 sprites for me, simultaneously using the pathfinding behavior would cause slowdown.

    Also, it would take a good amount of memory to implement it with 100 soldiers. Line of sight might be a better option for what you're trying to do. Try it with 20 soldiers first and see how it goes.

    Create a text and use this:

    "fps: "&fps&newline&"Cpu: "&cpuutilisation&newline&"Mem: "&ImageMemoryUsage

    line to track your memory and slowdowns. If it's too much slowdown, you may want to implement a more stupid ai first

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • i understand. did debate line of sight. but is the ai moves into the battlefield then find someone in there line of sight which will most likely be a minimum of 3 depending on how big the line of sight is how will it know which one to go for e.g. nearest. or is it a behavior? also lets say i have 2 minions fighting at the top of screen and one is left remaining at top and one at the bottom how will i make line of sight recognizable that there is a troop to fight down there. hope this makes sense.

    p.s im thinking of making a battle system bit like royal heroes if you ever played it. if not its free on kongregate as well as purchasable on steam

    update: im trying to use line of sight and set up when it detects a object but it doesnt give me an option or none i can see to go to the object it just detected. unless they is a way to return the uid of the object its just seen but i have no idea. so i general i dont know how to go to the object i just seen without it going to another object with the same sprite. also im using line on sight to detect families because there are so many objects to detect and the closest type of enemy might change so it would cause an event collision

  • anyone pleasE?

  • You need an family Boolean 'InBatlle'. When they start a battle, set the Boolean to true. False when they stop fightiing.

    Now.

    I dont know how you currently check when they stop fighting. So

    Event --- When they stop fighting.

    --------------- Call function "ride"

    New event

    On function "ride"

    Local variable 'Pos_X'

    Local variable 'Pos_Y'

    ------sub > every tick

    -----------------------Set those locals to the position of the object that stopped with fighting.

    ------sub > system > pick all family

    ------ > Family > Is boolean instance variable 'InBatlle' set > inverted. This picks all those that are not in a fight.

    -------> Family > Pick nearest (to position Pos_x and Pos_y.

    ----------------------- Find path to falily.x and family.y

    New event

    -> family > on path found

    -----------------------Follow path

    -----------------------Set InBatlle to false

    Now they will find a path to the nearest.

    To make em find a new path, every so much time.

    New event.

    -> family > is moving along path

    Sytem > compare two values > Family.Pathfinding.CurrentNode = 2 (zero based, so when it starts moving to the second index)

    --------------------------Call function "ride"

    Now they dont find paths at the same time, and not to often.

  • thank you so much for replying ive been trying to get turret behavior to work but to no prevail so ill give this a go.

  • cant seem to get it to work when i debug it. says demons have found path but wont move here is a screenshot.

    im sorry to be pain this is first time ive tried something like this but its completely stopping my project.

    Many Thanks

    Update: i did another test to allow the unit to rotate which actually made the troop move towards the enemy but this brings up 2 problems

    1. i dont want the troop to rotate as im using a sideview troop which looks way so is there a way maybe to use custom movement

    2. the unit once reaches troop keeps moving in same direction and not updating.

    also if i gave family the local variable for Pos_X and Pos_Y and change the events to these local varibles would it work?

  • I made a capital error. You have to pass the UID in a parameter to the function. Ans (re)pick that sprite by UID, beeing the parameter. Sorry, a bit difficult so without writing the actual code.

    You set the boolean to true, in 'on find' path. So it again keeps searching for a path every tick again, making the same error as you come from.

    Why did't you implement the last part of my suggestion ?

    Might be better if you drop the capx.

  • hi there i did end up adding the end part of the suggestion. didn't help great deal i think. but sorry im trying to understand the code and struggling but here is the capx file.

    u can also see i tried something else which failed

  • I dont know how to help you with that. How ever way i advance (while running the game) to the 'BattlefieldHK1' layout. There are no demons and there are no humans in the layout.

  • oh sorry about that let me quickly set it all up for you

    heres a new capx with everything set up so when u enter game. press map in bottom right and after 10 secs an enemy will attack and after it reaches base 3 secs later it will go to battle

  • I dont understand your capx. Kinda hell to debug. So many objects, so many globals. You should use more instances and different animations. Each instance, in stead of again a new object, is 30 % code less. 30 % less errors. 30% less headaches. My opinion.

    So let me show you (one of the many) way(s) to pathfind in a way that it does not looks for a path every tick.

    I hope you see the easy use of instances.

    And i offer you a very easy way to organise things in an array. I have no idea how you ever gonna balance the troupes in your logic flow. So many variables to change for so many objects in so much code. Look at how easy it gonna be this way.

    Hope i helped you, without disturbing.

  • thank you very much for your time and help and yeah i know its bad im always trying to adapt and use new things ive learnt to make things better. i really really do appreciate all the help youve offered me. also did u do a capx? im not sure where to find it?

  • Yeah i am that idiot that forgot his capx. So familiar.

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

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