Skip to main content
Added Setup 3. Also added some inline code formatting to explicitly refer to Box2D joints.
Source Link
NauticalMile
  • 1.7k
  • 11
  • 20

UPDATE: over the years I've become a bit more knowledgeable, and I realized Setup 2 can be modeled in a simpler way. I've added Setup 3, which I believe is the best solution.

Your question inspired me to play around with the RUBE editor to find a nice solution. Here's what I came up with:

  1. A wheel body that can roll back and forth
  2. A small box (chassis) attached to the wheel via a revolute jointb2RevoluteJoint. The chassis body is not allowed allowed to rotate.
  3. A main UFO body (no rotation)
  4. A prismatic joint connectingb2PrismaticJoint connecting the centers chassis and UFO body (this makes sure the UFO is is always upright)
  5. A distance jointb2DistanceJoint connecting the centers of the chassis chassis and the UFO body. This allows the UFO to bob up and down and eventually eventually settle on a set distance from the chassis (how fast this happens happens depends on the frequency and damping ratio).
  1. Distanceb2Distance and prismatic jointsb2PrismaticJoints from before are now connected to a small, intermediate body which still has rotation disallowed.
  2. The new intermediate body is connected via revolute jointb2RevoluteJoint to the main UFO body. The UFO body is now allowed to rotate.
  3. In order to constrain the UFO body from freewheeling, we need to stabilize it. Fortunately the method for doing so was already determined in this answer. The four distance joints are attached to the main UFO body and the new intermediate body. However, when playing around with the UFO in RUBE, I noticed that the parallel distance joint configuration as suggested in that answer was unstable, and it kept 'snapping' into the cross configuration seen in the above image. Since that was much more stable, I decided to go with it.

UFO2 gif

Setup 3

Setup 2 is a little bit complicated, and a slightly better setup can be achieved with fewer bodies and joints:

UFO 3

  1. Wheel, same as before.
  2. This time around, the wheel is connected to body 3 using a b2WheelJoint. This negates the need for the chassis body from the first two setups. The PrismaticJoint is also no longer needed, as its behavior is built in to the b2WheelJoint.
  3. A small intermediate body is still needed to connect the wheel to the main body. This body has the fixed rotation flag set for two reasons: it keeps the UFO upright (by fixing the vertical axis between the wheel and itself) and it provides the constant reference angle for the main body.
  4. The small body at position 3 is connected to the main body through a b2WeldJoint. The b2WeldJoint is primarily used to 'glue to bodies together', but here the constraint can be made soft by selecting the frequency and damping in a similar manner to the b2DistanceJoint.
  5. The main UFO body.

UFO 3 gif

This setup has done away with 3 joints and 1 body compared to Setup 2. All of the joint anchors are now placed in logical locations on the model, as opposed to those floating b2DistanceJoint anchor positions in Setup 2, which should be much simpler to construct and debug in actual game code. Finally, Setup 3 also has the bonus of not over shooting when the wheel runs into a barrier; notice how in the Setup 2 the UFO body overshoots the wheel position an snaps back when the wheel runs into an obstacle at high speed? The bottom b2RevoluteJoint is separating under the load. This doesn't happen to the b2WheelJoint in Setup 3.

Your question inspired me to play around with the RUBE editor to find a nice solution. Here's what I came up with:

  1. A wheel body that can roll back and forth
  2. A small box (chassis) attached to the wheel via a revolute joint. The chassis body is not allowed to rotate
  3. A main UFO body (no rotation)
  4. A prismatic joint connecting the centers chassis and UFO body (this makes sure the UFO is always upright)
  5. A distance joint connecting the centers of the chassis and the UFO body. This allows the UFO to bob up and down and eventually settle on a set distance from the chassis (how fast this happens depends on the frequency and damping ratio).
  1. Distance and prismatic joints from before are now connected to a small, intermediate body which still has rotation disallowed.
  2. The new intermediate body is connected via revolute joint to the main UFO body. The UFO body is now allowed to rotate.
  3. In order to constrain the UFO body from freewheeling, we need to stabilize it. Fortunately the method for doing so was already determined in this answer. The four distance joints are attached to the main UFO body and the new intermediate body. However, when playing around with the UFO in RUBE, I noticed that the parallel distance joint configuration as suggested in that answer was unstable, and it kept 'snapping' into the cross configuration seen in the above image. Since that was much more stable, I decided to go with it.

UFO2 gif

UPDATE: over the years I've become a bit more knowledgeable, and I realized Setup 2 can be modeled in a simpler way. I've added Setup 3, which I believe is the best solution.

Your question inspired me to play around with the RUBE editor to find a nice solution. Here's what I came up with:

  1. A wheel body that can roll back and forth
  2. A small box (chassis) attached to the wheel via a b2RevoluteJoint. The chassis body is not allowed to rotate.
  3. A main UFO body (no rotation)
  4. A b2PrismaticJoint connecting the centers chassis and UFO body (this makes sure the UFO is always upright)
  5. A b2DistanceJoint connecting the centers of the chassis and the UFO body. This allows the UFO to bob up and down and eventually settle on a set distance from the chassis (how fast this happens depends on the frequency and damping ratio).
  1. b2Distance and b2PrismaticJoints from before are now connected to a small, intermediate body which still has rotation disallowed.
  2. The new intermediate body is connected via b2RevoluteJoint to the main UFO body. The UFO body is now allowed to rotate.
  3. In order to constrain the UFO body from freewheeling, we need to stabilize it. Fortunately the method for doing so was already determined in this answer. The four distance joints are attached to the main UFO body and the new intermediate body. However, when playing around with the UFO in RUBE, I noticed that the parallel distance joint configuration as suggested in that answer was unstable, and it kept 'snapping' into the cross configuration seen in the above image. Since that was much more stable, I decided to go with it.

UFO2 gif

Setup 3

Setup 2 is a little bit complicated, and a slightly better setup can be achieved with fewer bodies and joints:

UFO 3

  1. Wheel, same as before.
  2. This time around, the wheel is connected to body 3 using a b2WheelJoint. This negates the need for the chassis body from the first two setups. The PrismaticJoint is also no longer needed, as its behavior is built in to the b2WheelJoint.
  3. A small intermediate body is still needed to connect the wheel to the main body. This body has the fixed rotation flag set for two reasons: it keeps the UFO upright (by fixing the vertical axis between the wheel and itself) and it provides the constant reference angle for the main body.
  4. The small body at position 3 is connected to the main body through a b2WeldJoint. The b2WeldJoint is primarily used to 'glue to bodies together', but here the constraint can be made soft by selecting the frequency and damping in a similar manner to the b2DistanceJoint.
  5. The main UFO body.

UFO 3 gif

This setup has done away with 3 joints and 1 body compared to Setup 2. All of the joint anchors are now placed in logical locations on the model, as opposed to those floating b2DistanceJoint anchor positions in Setup 2, which should be much simpler to construct and debug in actual game code. Finally, Setup 3 also has the bonus of not over shooting when the wheel runs into a barrier; notice how in the Setup 2 the UFO body overshoots the wheel position an snaps back when the wheel runs into an obstacle at high speed? The bottom b2RevoluteJoint is separating under the load. This doesn't happen to the b2WheelJoint in Setup 3.

replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/
Source Link

Your question inspired me to play around with the RUBE editor to find a nice solution. Here's what I came up with:

Setup 1

RUBE UFO 1

Let's start with the simpler one on the left. It has the following setup (from the bottom up):

  1. A wheel body that can roll back and forth
  2. A small box (chassis) attached to the wheel via a revolute joint. The chassis body is not allowed to rotate
  3. A main UFO body (no rotation)
  4. A prismatic joint connecting the centers chassis and UFO body (this makes sure the UFO is always upright)
  5. A distance joint connecting the centers of the chassis and the UFO body. This allows the UFO to bob up and down and eventually settle on a set distance from the chassis (how fast this happens depends on the frequency and damping ratio).

The result:

UFO1 gif

The idea would be to only render the ufo part, and use collision filtering so the rest of the physics in your game (with the exception of the ground) does not interact with the wheel part. In the gif you can see that the wheel doesn't climb over other bodies (as it shouldn't), so if you want to include steps in your game then you need to add hidden ramps and/or change the shape of the physics ground so that the wheel can climb up the steps.

Setup 2

If you want more than just vertical motion, then I recommend the second setup: enter image description here

This case is the same as the first, with the following ammendments:

  1. Distance and prismatic joints from before are now connected to a small, intermediate body which still has rotation disallowed.
  2. The new intermediate body is connected via revolute joint to the main UFO body. The UFO body is now allowed to rotate.
  3. In order to constrain the UFO body from freewheeling, we need to stabilize it. Fortunately the method for doing so was already determined in this answerthis answer. The four distance joints are attached to the main UFO body and the new intermediate body. However, when playing around with the UFO in RUBE, I noticed that the parallel distance joint configuration as suggested in that answer was unstable, and it kept 'snapping' into the cross configuration seen in the above image. Since that was much more stable, I decided to go with it.

The result:

UFO2 gif

Whatever you end up doing, I highly recommend trying it out in RUBE, its a great way to try and find fun feeling physics solutions.

Your question inspired me to play around with the RUBE editor to find a nice solution. Here's what I came up with:

Setup 1

RUBE UFO 1

Let's start with the simpler one on the left. It has the following setup (from the bottom up):

  1. A wheel body that can roll back and forth
  2. A small box (chassis) attached to the wheel via a revolute joint. The chassis body is not allowed to rotate
  3. A main UFO body (no rotation)
  4. A prismatic joint connecting the centers chassis and UFO body (this makes sure the UFO is always upright)
  5. A distance joint connecting the centers of the chassis and the UFO body. This allows the UFO to bob up and down and eventually settle on a set distance from the chassis (how fast this happens depends on the frequency and damping ratio).

The result:

UFO1 gif

The idea would be to only render the ufo part, and use collision filtering so the rest of the physics in your game (with the exception of the ground) does not interact with the wheel part. In the gif you can see that the wheel doesn't climb over other bodies (as it shouldn't), so if you want to include steps in your game then you need to add hidden ramps and/or change the shape of the physics ground so that the wheel can climb up the steps.

Setup 2

If you want more than just vertical motion, then I recommend the second setup: enter image description here

This case is the same as the first, with the following ammendments:

  1. Distance and prismatic joints from before are now connected to a small, intermediate body which still has rotation disallowed.
  2. The new intermediate body is connected via revolute joint to the main UFO body. The UFO body is now allowed to rotate.
  3. In order to constrain the UFO body from freewheeling, we need to stabilize it. Fortunately the method for doing so was already determined in this answer. The four distance joints are attached to the main UFO body and the new intermediate body. However, when playing around with the UFO in RUBE, I noticed that the parallel distance joint configuration as suggested in that answer was unstable, and it kept 'snapping' into the cross configuration seen in the above image. Since that was much more stable, I decided to go with it.

The result:

UFO2 gif

Whatever you end up doing, I highly recommend trying it out in RUBE, its a great way to try and find fun feeling physics solutions.

Your question inspired me to play around with the RUBE editor to find a nice solution. Here's what I came up with:

Setup 1

RUBE UFO 1

Let's start with the simpler one on the left. It has the following setup (from the bottom up):

  1. A wheel body that can roll back and forth
  2. A small box (chassis) attached to the wheel via a revolute joint. The chassis body is not allowed to rotate
  3. A main UFO body (no rotation)
  4. A prismatic joint connecting the centers chassis and UFO body (this makes sure the UFO is always upright)
  5. A distance joint connecting the centers of the chassis and the UFO body. This allows the UFO to bob up and down and eventually settle on a set distance from the chassis (how fast this happens depends on the frequency and damping ratio).

The result:

UFO1 gif

The idea would be to only render the ufo part, and use collision filtering so the rest of the physics in your game (with the exception of the ground) does not interact with the wheel part. In the gif you can see that the wheel doesn't climb over other bodies (as it shouldn't), so if you want to include steps in your game then you need to add hidden ramps and/or change the shape of the physics ground so that the wheel can climb up the steps.

Setup 2

If you want more than just vertical motion, then I recommend the second setup: enter image description here

This case is the same as the first, with the following ammendments:

  1. Distance and prismatic joints from before are now connected to a small, intermediate body which still has rotation disallowed.
  2. The new intermediate body is connected via revolute joint to the main UFO body. The UFO body is now allowed to rotate.
  3. In order to constrain the UFO body from freewheeling, we need to stabilize it. Fortunately the method for doing so was already determined in this answer. The four distance joints are attached to the main UFO body and the new intermediate body. However, when playing around with the UFO in RUBE, I noticed that the parallel distance joint configuration as suggested in that answer was unstable, and it kept 'snapping' into the cross configuration seen in the above image. Since that was much more stable, I decided to go with it.

The result:

UFO2 gif

Whatever you end up doing, I highly recommend trying it out in RUBE, its a great way to try and find fun feeling physics solutions.

Bounty Awarded with 50 reputation awarded by Anko
Source Link
NauticalMile
  • 1.7k
  • 11
  • 20

Your question inspired me to play around with the RUBE editor to find a nice solution. Here's what I came up with:

Setup 1

RUBE UFO 1

Let's start with the simpler one on the left. It has the following setup (from the bottom up):

  1. A wheel body that can roll back and forth
  2. A small box (chassis) attached to the wheel via a revolute joint. The chassis body is not allowed to rotate
  3. A main UFO body (no rotation)
  4. A prismatic joint connecting the centers chassis and UFO body (this makes sure the UFO is always upright)
  5. A distance joint connecting the centers of the chassis and the UFO body. This allows the UFO to bob up and down and eventually settle on a set distance from the chassis (how fast this happens depends on the frequency and damping ratio).

The result:

UFO1 gif

The idea would be to only render the ufo part, and use collision filtering so the rest of the physics in your game (with the exception of the ground) does not interact with the wheel part. In the gif you can see that the wheel doesn't climb over other bodies (as it shouldn't), so if you want to include steps in your game then you need to add hidden ramps and/or change the shape of the physics ground so that the wheel can climb up the steps.

Setup 2

If you want more than just vertical motion, then I recommend the second setup: enter image description here

This case is the same as the first, with the following ammendments:

  1. Distance and prismatic joints from before are now connected to a small, intermediate body which still has rotation disallowed.
  2. The new intermediate body is connected via revolute joint to the main UFO body. The UFO body is now allowed to rotate.
  3. In order to constrain the UFO body from freewheeling, we need to stabilize it. Fortunately the method for doing so was already determined in this answer. The four distance joints are attached to the main UFO body and the new intermediate body. However, when playing around with the UFO in RUBE, I noticed that the parallel distance joint configuration as suggested in that answer was unstable, and it kept 'snapping' into the cross configuration seen in the above image. Since that was much more stable, I decided to go with it.

The result:

UFO2 gif

Whatever you end up doing, I highly recommend trying it out in RUBE, its a great way to try and find fun feeling physics solutions.