How do I

Get help using Construct 2

Post » Sun Sep 25, 2016 4:48 pm

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.
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Sun Sep 25, 2016 6:07 pm

"----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
Image Image Image
B
31
S
11
G
27
Posts: 748
Reputation: 17,093

Post » Sun Sep 25, 2016 6:35 pm

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
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Mon Sep 26, 2016 11:11 am

anyone pleasE?
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Tue Sep 27, 2016 3:02 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Sep 28, 2016 11:14 am

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.
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Wed Sep 28, 2016 11:58 am

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?
Last edited by darkrealos on Wed Sep 28, 2016 10:38 pm, edited 1 time in total.
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Wed Sep 28, 2016 1:32 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Sep 28, 2016 3:20 pm

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 :D
Last edited by darkrealos on Wed Sep 28, 2016 10:39 pm, edited 1 time in total.
B
19
S
6
Posts: 143
Reputation: 1,835

Post » Wed Sep 28, 2016 3:49 pm

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.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Next

Return to How do I....?

Who is online

Users browsing this forum: BackendFreak, dand and 31 guests