How do I Create Physics Structures

0 favourites
  • 14 posts
From the Asset Store
a complete set of modular graphics, perfect for all kind of levelbuilding
  • I want to create structures such as this:

    To be created randomly out of physics objects.

    I'm having a spot of bother with physics joints. Lets say the lighter square is the centre object, this has 4 image points on each side, I want to attach a random number of collars to random sides of the centre object, and then stick them together with a joint. I then want more large squares to spawn off the collars and so on and on until I have this one joined structure.

    My problems in testing are that even though I am ignoring collisions between the objects, when I spawn a collar off an image point of a square then set its angle relative to that of the face of the square it's spawned at, when I apply a limited revolving joint, the item spins to an angle then sets facing an awkward direction.

    I don't quite know the best theory for achieving something like this. My reason for wanting to use physics is so that I can influence the whole generated structure as one by external forces.

  • I remember having trouble with limited revolute joints a while back when doing a ragdoll. I think what I was doing wrong then was using absolute angles for the rotation limits when they should be relative to the object's default zero degree position (i think). Anyway here's what it looked like:

    https://dl.dropboxusercontent.com/u/523 ... Joints.png

    I hope this is going to be a space station for your mining game <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • I think the angles of freedom of a limited revolute joint are relative to the angle from ObjA to ObjB, at time the joint was created.

  • mattb / thanks I'm still trying to work this out, i'll share a capx later if anyone is interested.

    mattb - might have something to do with mining :b

  • I think what's unintuitive, or little known, is that you can add positive and negative numbers into the parameters windows when setting up the joint. Have a look at this simple example to see what I mean.

  • Colludium / mattb

    I see what you mean there Colludium. I struggled with this for a while but it's pretty complex and messy. Problem is first generating the physics objects, setting the angle, then applying the joint relative to that angle - which seems to for some reason cause all the objects to spin on the spot which then messes up the angle at which other parts of the structure are spawned...

    So I've brute forced it using the pin to object which is a real shame as the forces are not relative to the core object it's entirely arbitrary. Also the structures aren't being generated, they're hand-made but you can get an idea for what I'm trying to do with this demo:

    https://dl.dropboxusercontent.com/u/3317708/Space%20Lander%200.1/index.html

    Use WASDQE to thrust in various directions, hold shift to stabilise. R restarts layout.

    Match angle, watch the speed

  • If you move physics objects (using non-physics events) after they have been declared to the physics engine then they are given huge velocities because of the distance they move in one tick. If you move them you need to subsequently assign them zero velocity to negate this effect.

  • Colludium - ah I didn't know that, interesting. Will let you know how I get on.

  • Colludium - so I'd 'set angle' and then 'set angular velocity' to 0 sort of thing?

  • If you've moved either object then it's worth setting velocity first, then create the joint. The order of events might not matter, but I think that's the most logical.

  • Try Construct 3

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

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

    I had a quick go at making a lattice structure like in your first image using both the stock physics & chipmunk behaviors. It's possible to joint everything together, but once you apply a force to the structure the physics starts madly shaking. This was jointing everything to a central sprite, all sprites not colliding.

    You could try a more triangulated jointing between the components, that might help, but I've got a feeling that these massive linkages will never work.

    Maybe they could be non-colliding things in the background, with selected areas that you can dock with, or have a single collision polygon with all the structure sprites pinned to it?

  • This is a situation where joints wouldn't really cut it. The box2d and chipmunk libraries let you attach multiple shapes onto the same physics object, which is like a perfectly rigid joint. The only work needed is calculating the center of mass and inertia of the object as shapes are added/removed.

    It's probably easier to to do by accessing the js libraries themselves to do it rather than using the behaviors. Not to mention it would give more control.

  • mattb - Thanks for having a crack at it Matt, not sure I get what you mean by the single collision polygon method?

    R0J0hound - I see what you're saying, however this is something I've never attempted and wouldn't really know where to start with the JS libraries.

  • I meant you just have everything pinned to one big collision poly (either built manually or using some setup that generates a collision hull for the polygon plugin).

    Something that physics sims are really good for in random 'dungeon' generation is spacing out a bunch of rooms. Spawn a cluster of shapes & run the simulation for a while:

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