mojo3d Physics Samples

About Monkey 2 Forums Monkey 2 Code Library mojo3d Physics Samples

This topic contains 11 replies, has 3 voices, and was last updated by  DruggedBunny 2 weeks ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #12875

    DruggedBunny
    Participant

    Just posting some simple mojo3d samples using Bullet physics. Feel free to add more!

    My first two samples just implement a basic wrapper called PhysBox, specific to cube bodies.

    Example 1: Simple box with vertical boost and spin

    #12876

    DruggedBunny
    Participant

    Example 2: Wall of boxes

    #12877

    DruggedBunny
    Participant

    Try turning off shadows in second demo if lots of boxes cause slowdown on your system!

    #12878

    DruggedBunny
    Participant

    Make boxes bouncy by adding this in PhysBox.Start:

    #12879

    DruggedBunny
    Participant

    Also, note that red boxes dropped via “D” in wall sample may stop responding when Space is pressed — this is intentional, and is the default behaviour of RigidBody — bodies well away from others will auto-sleep until hit again to reduce processing.

    Pass False to Start () call in DropBoxes to disable sleeping!

    #12882

    cocon
    Participant

    Cool samples! 🙂

    #12891

    Xaron
    Participant

    Very cool stuff, thanks for adding!

    #12898

    DruggedBunny
    Participant

    Thanks, hopefully it might help others start playing with this stuff!

    #12999

    DruggedBunny
    Participant

    This sample adds a lintel or “top bit” to the wall, and finally adds shooting via Space bar!

    Demonstrates how to orientate a bullet from the camera (or gun) and apply impulse force.

    Code’s getting a bit messy, but hey-ho.

    Example 3: Wall of boxes and SHOOTING ACTION!

    #13147

    DruggedBunny
    Participant

    This is an update to Sample 2, wall of boxes. (No shooting in this one!)

    I found that the original gradually slides apart over around 3-4 minutes (faster if no vsync), due to all boxes being forced to remain active, rather than using the default sleep timer to deactivate them.

    I’d done this because if they fell asleep, per the default behaviour, pressing Space would not wake them up again, so instead of rising up they would just sit still, unless hit by another box.

    This version uses the default sleep timeout, but now when you hit Space, it wakes all boxes so they can rise up, yet it allows the wall to be much more stable by default.

    I’ve also added colour-coding, so that you can see the current physics state. If you do nothing, all boxes will turn orange after a few seconds.

    Use Space to ‘boost’ all boxes, or D to drop boxes into the scene. (DropBox now uses a timer to limit number of boxes per second.)

    Fun challenge: boost the wall off the top of the screen and try land it again without it all collapsing!

    Note for non-native English speakers: “nodding off” means falling asleep! This is the state where Bullet Physics is sampling an object’s movement to see if it should be deactivated.

    Example 4: Wall of boxes showing sleep states

    #13222

    DruggedBunny
    Participant

    These won’t work with latest Github ‘develop’ branch — however, the only change needed should be in OnRender:

    From…

    scene.Render (canvas, cam)

    To…

    cam.Render (canvas)

    Optionally, in Example 3, you can delete the whole Class Entity Extension and replace…

    pb.model.RemoveParent ()

    … with:

    pb.model.Parent = Null

    I’ll update the samples here once the itch.io release includes these changes.

    #13595

    DruggedBunny
    Participant

    Updated all samples to work with latest Patreon subscriber release/latest Github develop branch.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.