How do I ; Chipmunks + rts

Get help using Construct 2

Post » Mon Sep 28, 2015 1:00 pm

I was thinking about a force-based rts movement thing the other day. This is how I'd do it, & I'm sure it could efficiently handle movement, collision & pathing for hundreds of units:
Image
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Post » Mon Sep 28, 2015 1:39 pm

mattb wrote:I was thinking about a force-based rts movement thing the other day. This is how I'd do it, & I'm sure it could efficiently handle movement, collision & pathing for hundreds of units:
Image


If you could pull it off and share, that would be neat. Otherwise, have no clue how to implement it.

I have one more idea: maybe having a single sprite with pathfinding, to which position object with physics is always positioned. Then other selected units joint to that main one, or in chain, one after the other. Or groups within selected group.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
85
S
27
G
20
Posts: 1,961
Reputation: 18,649

Post » Mon Sep 28, 2015 3:03 pm

THat's way too complicated & janky, seriously just have a go at what I described - it's not that complex, maybe 20 events tops, plus you'd learn about everything you need to know about c2 events in the process :)

I would start by doing this:

- decide how you want to do level design (tilemap or separate sprites for collision boxes), screen resolution etc, then lay out a quick map. Give your solids the chipmunk behavior & set to immovable. I usually make a family called fPhys with chipmunk applied, then put physics objects into it instead of applying it to each one.

-make a single unit sprite, add to fPhys to give it the chipmunk behavior, set circular collision shape, give it a 'moving' boolean, a 'maxspeed' var & an 'accel' var (you'll need to play with those values).

-make an array of size 0,1,1 called PathList & add the Unit to a container with it.

-make another sprite offscreen with the pathfinding behavior called Pathfinder, set up it's cellsize to work with your level.

-make a circular sprite called PathNode, these will be the blue circles seen above.

-OnStart:
set fPhys chipmunk gravity to 0,0
set Unit.chipmunk.maxspeed to its maxspeed var

-make a mouse onClick event > set PathList to size 0,1,1 (to reset it) > set Pathfinder to Unit position > pathfind to the mouse pos > on path found, for each path point create a PathNode sprite & 'push front' its UID into the PathList array to build a queue of nodes the unit will visit > set Unit 'moving' var to true.

-every tick the unit is moving:
PathList.width= 0, set Unit.moving to false
else
pick PathNode by UID Pathlist.back > apply a chipmunk force of Unit.accel towards PathNode xy
Unit is overlapping PathNode & that node is in its PathList > clear the UID at that index in the list


Something like that should be enough to get you started, then move on to multiple units, selection system, change size of PAthNodes based on selection size...
B
27
S
12
G
1
Posts: 157
Reputation: 3,359

Post » Mon Sep 28, 2015 5:35 pm

megatronx wrote:
edit@ @R0J0hound The @Prominent example doesn't seam to work https://www.dropbox.com/s/9286l0hy9pp9etk/tst.capx?dl=0


I fixed your capx: http://1drv.ms/1P1WOhr
You were doing various things wrong.
You set the joint at 0x0y of the layout(not the object).
You also have to move the object to the pathfinding object first before connecting them I think.
You had the object all on the same physics layer, so they were colliding.
I also, changed the joint type to a dampened spring, adjust the mass of the blue objects, dampened their velocities so they don't stay springy..
Also changed them to circles which should help with collisions, but might be fine either way.
..You might also want to consider putting these into a family and put the physics behavior on the family, in-case you plan to have multiple sprites/objects using physics together.
B
41
S
19
G
65
Posts: 1,085
Reputation: 37,842

Post » Mon Sep 28, 2015 5:50 pm

Prominent wrote:
megatronx wrote:
edit@ @R0J0hound The @Prominent example doesn't seam to work https://www.dropbox.com/s/9286l0hy9pp9etk/tst.capx?dl=0


I fixed your capx: http://1drv.ms/1P1WOhr
You were doing various things wrong.
You set the joint at 0x0y of the layout(not the object).
You also have to move the object to the pathfinding object first before connecting them I think.
You had the object all on the same physics layer, so they were colliding.
I also, changed the joint type to a dampened spring, adjust the mass of the blue objects, dampened their velocities so they don't stay springy..
Also changed them to circles which should help with collisions, but might be fine either way.
..You might also want to consider putting these into a family and put the physics behavior on the family, in-case you plan to have multiple sprites/objects using physics together.


Well thank you! I will check it out.

[email protected] it works nicely so far. Will think of making this multi-unit and selectable.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
85
S
27
G
20
Posts: 1,961
Reputation: 18,649

Post » Mon Sep 28, 2015 7:32 pm

@Prominent I added couple of obstacles and was trying to figure out how to make units follow trough,also using the nodes idea, but I have no clue how we would make units move to those nodes?

https://drive.google.com/file/d/0B0jUjW ... sp=sharing
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
85
S
27
G
20
Posts: 1,961
Reputation: 18,649

Post » Mon Sep 28, 2015 9:36 pm

@megatronx , I would probably try to cycle through the nodes, finding the node closest to the destination that is in the line of sight with the unit.
So I would check the last node to see if it is in sight, then continue with each consecutive node until it gets to a node it can see. I'd only do this if the object collides with a wall. Apply a force towards the node that is in sight.
If two units are fighting over a node, I would somehow apply force to only one of them (maybe the one closest to the destination)..
I'll try experimenting a little, but it might be something that requires more time to get right, and not sure if I can do too much.
B
41
S
19
G
65
Posts: 1,085
Reputation: 37,842

Post » Mon Sep 28, 2015 10:22 pm

I experimented a bit, but didn't find any solutions. The issue I was facing is how to manage which unit attempts to go through the pathway first so that units don't compete with each other.
This would require more work to figure out than I'm willing to invest, since it basically means designing a way to store where each unit is, and how to process all of it so that they work with each other to get through.
One thing that comes to mind is using a dijkstra map instead of pathfinding, since that creates data that multiple units can use to move through a level. That way, each unit would have their own way of finding a path to the destination without generating one for each unit.

edit: also with a dijkstra map, the units would be moving towards the next tile rather than being pulled by something that could be currently behind a wall, so the flow of forces would be more accurate. You could also stop other units from trying to get to a tile if that tile is already occupied by another unit.
B
41
S
19
G
65
Posts: 1,085
Reputation: 37,842

Post » Tue Sep 29, 2015 9:32 am

Prominent wrote:I experimented a bit, but didn't find any solutions. The issue I was facing is how to manage which unit attempts to go through the pathway first so that units don't compete with each other.
This would require more work to figure out than I'm willing to invest, since it basically means designing a way to store where each unit is, and how to process all of it so that they work with each other to get through.
One thing that comes to mind is using a dijkstra map instead of pathfinding, since that creates data that multiple units can use to move through a level. That way, each unit would have their own way of finding a path to the destination without generating one for each unit.

edit: also with a dijkstra map, the units would be moving towards the next tile rather than being pulled by something that could be currently behind a wall, so the flow of forces would be more accurate. You could also stop other units from trying to get to a tile if that tile is already occupied by another unit.


You need to create an order. I think something like this might be a good start.
You need boolean that will lock the unit from picking. You also need a variable Order. This is for units that player has selected.

Repeat "selected" count, pick nearest Units to MouseTarget, units boolean Ready = false. Then set that boolean to true and varOrder to loopindex. Now every unit has it's order number, so it might be easier to figure out how to get them pass trough.

Maybe that will help. Also,have a look at Ro0j example.
My professional Royalty Free Music at Scirra Assets Store
--------------------------------
Specs: i5 2500, 16gb of ram, gtx 770, win 7, Focusrite Scarlett 8i6, Mackie mr8mk2, Alesis 320, browsing the net on chrome.
B
85
S
27
G
20
Posts: 1,961
Reputation: 18,649

Post » Tue Sep 29, 2015 5:21 pm

megatronx wrote:
You need to create an order. I think something like this might be a good start.
You need boolean that will lock the unit from picking. You also need a variable Order. This is for units that player has selected.

Repeat "selected" count, pick nearest Units to MouseTarget, units boolean Ready = false. Then set that boolean to true and varOrder to loopindex. Now every unit has it's order number, so it might be easier to figure out how to get them pass trough.

Maybe that will help. Also,have a look at Ro0j example.


The issue I see with this is that the nearest unit may not be the one that needs to move first.
Whenever you click to create a path, it removes the previous nodes, so if the units are following the nodes, and you click again in the same location or nearby, the previous nodes disappear and you get one or so nodes at the place where you clicked.
You would have to store/save/update each path nodes in some way so that they all connect and go to the destination from the perspective of each unit.
I don't know how much processing would occur to create a path for each unit- but that is one way to ensure each unit has a node to go to (you could put the path-following sprite in a container with the unit so that each unit has a path-following sprite).
Maybe at that point, you could find which unit has a shorter path, and move them in that order (short to long). If there is any congestion, pause the longer path units that are behind the congested area/unit.

edit: this is also why I suggest a dijkstra, because those take less processing, and you get data that an unlimited number of units can rely on. I made a dijkstra plugin in the past for something I was working on and I never released it because it wasn't meant for public use. I'd have to clean it up and figure out a way to make it more user friendly.. Maybe I'll do that in the future, but I have other things to focus on.
Using paths for each unit might be a workable solution, but you would have to test it out.
B
41
S
19
G
65
Posts: 1,085
Reputation: 37,842

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: plinkie, SERG 04, Yahoo [Bot] and 2 guests