How do I ; Chipmunks + rts

0 favourites
From the Asset Store
10 isometric and animated Strategy Game Buildings in two Colors.
  • Hey,

    A while back i reed that you can pair chipmunks physics with rts, for units not to walk on top of each other. Can someone tell me how to make it work that way?Thx!

  • You can attach the physics object to another physics object via a joint, and move one like so:

    also make sure the objects don't collide with each other.

    Then you would just move the object that needs to follow a path, and the physics object attached will get pulled.

    edit: the 10*sprite2.mass stuff should be 100 instead of 10.

  • I was searching around and didn't you ask this before in a way?

    Anyway can't this problem be simplified further?

    https://dl.dropboxusercontent.com/u/542 ... _push.capx

    Use a family to be able to pick two different instances and then just compare the distances between the two and then move them apart with the "move at angle" action if they're too close?

  • You can attach the physics object to another physics object via a joint, and move one like so:

    also make sure the objects don't collide with each other.

    Then you would just move the object that needs to follow a path, and the physics object attached will get pulled.

    edit: the 10*sprite2.mass stuff should be 100 instead of 10.

    Thx. Willlook in to it.

    I was searching around and didn't you ask this before in a way?

    Anyway can't this problem be simplified further?

    https://dl.dropboxusercontent.com/u/542 ... _push.capx

    Use a family to be able to pick two different instances and then just compare the distances between the two and then move them apart with the "move at angle" action if they're too close?

    Hi,

    Thx for example. Will examine it. But I have concern that it wont work well, if its based of example from example rts project. The issue in rts example is that pushingout is easy to glitch out,with just few clicks the units end up on topof each other. But will examine.

    Still I'm interested to see ho it would workwith physics. Bouncing out would be desirable too.

  • My capx will keep the enemies from piling up. If they are piled up they will spread out very quickly. The only drawback is they can be pushed into the walls a bit if things are crowded.

    Prominent's solution is to basically have a second object attached to the object with the pathfinder behavior. That bypasses the pathfinder overriding the physics positions, and probably is the best way to Incorporate physics. The rest is to stop the velocity of the objects so all we get is the pushing action. I'm unsure of the purpose of the force though.

  • My capx will keep the enemies from piling up. If they are piled up they will spread out very quickly. The only drawback is they can be pushed into the walls a bit if things are crowded.

    Prominent's solution is to basically have a second object attached to the object with the pathfinder behavior. That bypasses the pathfinder overriding the physics positions, and probably is the best way to Incorporate physics. The rest is to stop the velocity of the objects so all we get is the pushing action. I'm unsure of the purpose of the force though.

    Would you be able to make example with physics for me? I'd highly appreaciate it!

  • I'm unsure of the purpose of the force though.

    force was just to negate gravity, but I suppose the gravity could be turned off instead. Could probably also use different type of joint if you want it more springy. I don't know what would happen if you have multiple objects trying to pass each other, etc. They would probably bump into each other and try to get around- so a circular shaped physics object would help prevent them getting stuck. You could probably stop the path movement if a physics object gets too far away, to allow it to catch up, or even perform some other operation to walk through other objects, like changing the physics group it is in temporarily.

  • R0J0hound Ive checked your demo, but I can see it not working that tight in rts game :< Could I ask you for help again, to make a demo of rts movement with physics? Thx

  • Prominent

    Ah, that does make sense. I forgot about that.

    megatronx

    Doesn't Prominent's idea work?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Prominent

    Ah, that does make sense. I forgot about that.

    megatronx

    Doesn't Prominent's idea work?

    I'll check now. But even if it does, I have no clue how I could apply this to many units. Any suggestions?

    I'm thinking of such idea: out of selected units having only first unit pathfind, and the others are following either it or create a chain. How this could be done?

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

  • 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:

  • 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:

    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.

  • 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...

  • 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.

  • >

    >

    > 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.

    Editxsr@Yes it works nicely so far. Will think of making this multi-unit and selectable.

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