mojo3d: attempted box physics not working!

About Monkey 2 Forums Monkey 2 Programming Help mojo3d: attempted box physics not working!

This topic contains 5 replies, has 2 voices, and was last updated by  Mark Sibly 1 year, 10 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #9825

    DruggedBunny
    Participant

    I can’t tell why this isn’t working: it builds static and dynamic bodies (CreateStaticBox/CreateDynamicBox) from a model passed to it, and everything renders OK, but my dynamic box body falls through the static ground body!

    The method I use (using Model.Mesh.Bounds for New BoxCollider’s Boxf) works if I modify shapes.monkey2 to use ths method, so I don’t think that’s the problem, and hard-coding the sizes didn’t fix it (see commented-out returns in above functions)…

    Help!

    #9832

    Mark Sibly
    Keymaster

    I think the problem here is that SetScale doesn’t currently affect the physics, only the rendering, so the ground box looks big but is still only actually a unit cube as far as the phyics is concerned.

    I’ll have a think about how best to deal with this but for now thje BoxCollider size will need to be it’s ‘actual’ size.

    #9838

    DruggedBunny
    Participant

    Hi Mark, I thought that, but I’m not actually convinced!

    [IGNORE: See last post!]

    See my second paragraph — it works when I use that same method in shapes.monkey2, I think because I:

    1. create my box,
    2. resize it,
    3. pass that resized box (with, presumably, its resized .Bounds Boxf) to the collider setup.

    So, collider setup should be using the .Bounds of the resized box model at that point, not scaling after creating the collider. Try this (modded shapes.monkey2):

    [EDIT: See stripped-down version below.]

    Also, using hard-coded values didn’t work — see the commented-out return values in CreateStatc/DynamicBox in first example.

    #9843

    DruggedBunny
    Participant

    [IGNORE: See last post! But see comment about tweaking ANGLE const in this demo!]

    Here’s a stripped-down version of shapes.monkey2 showing mesh.bounds being used sucessfully for collider:

    This demo also highlights some weirdness I noticed in the original sometimes — change const ANGLE at the top to 10-20 and watch it settle at a strange angle!

    #9844

    DruggedBunny
    Participant

    Eek, maybe ignore all of this — my tweaked demo doesn’t use SetScale! Adding

    causes it to fall through. I assumed the bounds would be updated, then the collider built using that updated bounds (ie. thought you were referring to resizing not working after the collider is built), but apparently bounds stays fixed…

    #9845

    Mark Sibly
    Keymaster

    SetScale is an algorithmic entity scale factor used by the renderer. It does not affect actual mesh vertex positions (as stored in memory) therefore does not affect mesh bounds either. If there was an Entity.Bounds, it would probably affect that though!

    Mesh.TransformVertices and Mesh.FitVertices on the other hand *do* affect mesh vertex positions, so do affect  mesh bounds.

    In general, my advice for now would be to avoid SetScale if you’re using physics and build all your meshes at the right size in the first place. You can also use Mesh.FitVertices if you want to physically scale a mesh to a certain size etc.

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

You must be logged in to reply to this topic.