Jump to content

Parent-Child rotation and Box Collider of Child Problem


ian
 Share

Recommended Posts

Hi 
I have some problem with collider of child box. If we set parent box and add child box. If Child have its box collider, and if we rotate parent box, child is changing (potition and rotation), but child's box collider is not changing (position and rotation).

How should we achive that box-collider will follow child when we (rotate or maybe change position of parent).

Here is example of what I am talking about. (here is grid-box seen as box-collider of child-box. and grid-box is not changing position and rotation).
http://www.babylonjs-playground.com/#MBFUI#9

(or mybe http://www.babylonjs-playground.com/#MBFUI#8  - here we can se grid-boxes as colliders and blue box is rotation and changing position but it's box-collider is not)

How can/should we repair code so that box-collider is folowing its child's box-mesh?

Greetings
 
Link to comment
Share on other sites

:)  Not much action, eh?  Sorry.  For only $29.99/month, you can get the Premium Customer Service plan... with 24/7 live chat... for typing-in whining and impatience.  :D

(Wingnut just trying to do some comedy... probably failing.)

You're wanting to force-position/rotate... the child's physics imposter, yes?  (via parenting control)   hmm.

You MIGHT need to create a compoundImposter that is a "copy" of the positional/rotational relationship... of the mesh parent-child. 

In other words, the two components of the compound imposter... must be positioned and oriented identical-to the position/rotation relationship of the two actual mesh.  Not sure, though.  Speculating.

You want to "attach" the child's imposter... to the parent imposter.  Yes?  hmm. 

I'll keep thinking.  Be patient, if possible.  I put up a small Raanan curtain which should show impact with the child... (after compound imposter?).  hmm.

Perhaps try some things.  Find compound imposters in the playground searcher, and see how they are made and how they "act".  *shrug*

Update: http://www.babylonjs-playground.com/#MBFUI#13  I tried adding a compound in lines 91-98.  Also tried a few updates... 106 & 107.  No joy.  I'll keep testing.  We will get child impact with the curtain... even if it kills us.  :)  I am making some mistake, somewhere.  Compound SHOULD work.

Link to comment
Share on other sites

6 hours ago, Wingnut said:

:)  Not much action, eh?  Sorry.  For only $29.99/month, you can get the Premium Customer Service plan... with 24/7 live chat... for typing-in whining and impatience.  :D

(Wingnut just trying to do some comedy... probably failing.)

You're wanting to force-position/rotate... the child's physics imposter, yes?  (via parenting control)   hmm.

You MIGHT need to create a compoundImposter that is a "copy" of the positional/rotational relationship... of the mesh parent-child. 

In other words, the two components of the compound imposter... must be positioned and oriented identical-to the position/rotation relationship of the two actual mesh.  Not sure, though.  Speculating.

You want to "attach" the child's imposter... to the parent imposter.  Yes?  hmm. 

I'll keep thinking.  Be patient, if possible.  I put up a small Raanan curtain which should show impact with the child... (after compound imposter?).  hmm.

Perhaps try some things.  Find compound imposters in the playground searcher, and see how they are made and how they "act".  *shrug*

Update: http://www.babylonjs-playground.com/#MBFUI#13  I tried adding a compound in lines 91-98.  Also tried a few updates... 106 & 107.  No joy.  I'll keep testing.  We will get child impact with the curtain... even if it kills us.  :)  I am making some mistake, somewhere.  Compound SHOULD work.

winghu I solve this as you say. Things works now OK. 
Thank you.

Link to comment
Share on other sites

That's good news, Ian!  Did you use a compound imposter?  Can you fix our #13 playground?  That would be good.

Glad to hear you are rolling again.  Well done.

Update:  http://www.babylonjs-playground.com/#MBFUI#15

I just needed to add some restitution to _child.  :)  Also increased sizes.  _child should not go "through" cloth curtain.  Should push it out of the way, like a sphere imposter does.  I need to study that more.

In the next PG... I changed _parent and _child to sphereImpostors (and lowered restitution on both, and on curtain spheres). 

http://www.babylonjs-playground.com/#MBFUI#16

Boxes no longer go THROUGH curtain... but wow, restitution is acting VERY radical.  (But, then again, I suppose if a human used THAT MANY JOINTS, they would act radical, too.)  ar ar ar.  :)   But hmm.

I would not expect... that changing the impostor type in lines 96-97.... would make SO MUCH difference in the way the curtain acts.  But it does.  hmm.

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...

Here is playground
http://www.babylonjs-playground.com/#CKEHJ#0

Use keys WSAD to rotate mode (blue color).

 

I would like to comment // perplexus.physicsImpostor = new BABYLON.PhysicsImpostor( perplexus, BABYLON.PhysicsImpostor.MeshImpostor, { mass : 0, friction : 1, restitution : 0 }, scene);

and instead MeshImpostor use all colliders[a] as BABYLON.PhysicsImpostor.BoxImpostor

I do parenting but if I comment // perplexus.physicsImpostor = new BABYLON.PhysicsImpostor( perplexus, BABYLON.PhysicsImpostor.MeshImpostor, { mass : 0, friction : 1, restitution : 0 }, scene);

 

Ball fall throught and get

Uncaught TypeError: Cannot read property 'x' of undefined
    at RotateAround (eval at compileAndRun (index.js:188), <anonymous>:87:65)
    at e.poskrbiZaRotacijo [as callback] (eval at compileAndRun (index.js:188), <anonymous>:66:4)
    at e.notifyObservers (babylon.js:2)
    at i.render (babylon.js:12)
    at index.js:179
    at n._renderLoop (babylon.js:4)

Can anybody HELP ME SOLVE THIS PROBLEM?

for (var a=0; a<colliders.length; a++) {
  colliders[a].isVisible = true;
  // 1. parenting !!!
  colliders[a].parent = perplexus;
  // 2. set physicsImpostor !!!
  colliders[a].physicsImpostor = new BABYLON.PhysicsImpostor( colliders[a], BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0, friction : 1, restitution : 0 }, scene);
  //colliders[a].physicsImpostor.forceUpdate();
  colliders[a].checkCollisions = true;
}

@RaananW

Link to comment
Share on other sites

Hi Ian,

Reviving an old topic :)

It is very hard for me to follow the code and understand what everything does. I understand from what you are writing that you are trying to create a compound mesh instead of the meshimpostor? want to create a simpler playground with 2 versions - one with the error visible so I can understand better?

Link to comment
Share on other sites

Uncaught TypeError: Cannot read property 'x' of undefined
    at RotateAround (eval at compileAndRun (index.js:188), <anonymous>:87:65)
    at e.poskrbiZaRotacijo [as callback] (eval at compileAndRun (index.js:188), <anonymous>:66:4)
    at e.notifyObservers (babylon.js:2)
    at i.render (babylon.js:12)
    at index.js:179
    at n._renderLoop (babylon.js:4)

This error is gone. "I think the problem was because quaternion..."

perplexus.rotationQuaternion = new BABYLON.Quaternion();

(I think this line define perplexus to behave rotation like quaternion).

(But I see somewhere that there are 2 different quaternion one like babylon_quaternion and second like physics_quaternion. "Am I right? Are babylon and physics quaternion same")

But the main problem is that pareting BoxImpostor physics boxes are not working. I think that BabalonJS dosn't support parenting physicsImpostors.

if (newMesheI.id == "Path") {
                perplexus = newMesheI;
                //perplexus.checkCollisions = true;
                //perplexus.physicsImpostor = new BABYLON.PhysicsImpostor( perplexus, BABYLON.PhysicsImpostor.MeshImpostor, { mass : 0, friction : 1, restitution : 0 }, scene);
                perplexus.rotationQuaternion = new BABYLON.Quaternion();

                perplexusWorldMatrixBegin = perplexus.getWorldMatrix();
            }
            if ( newMesheI.id.substring(0, 4) == "Cube") {
                colliders.push( newMesheI );
            }
            if (newMesheI.id == "Sphere") {
                playBall = newMesheI;
                playBall.checkCollisions = true;
                playBall.physicsImpostor = new BABYLON.PhysicsImpostor( playBall, BABYLON.PhysicsImpostor.SphereImpostor, { mass : 5, friction : 1, restitution : 0 }, scene); // 0.597=metal ball
            }
        }

       // this code below parenting each collider box as child of perplexus mesh.

        for (var a=0; a<colliders.length; a++) {
            colliders[a].isVisible = true;
            // 1. parenting !!!
            colliders[a].parent = perplexus;
            // 2. set physicsImpostor !!!
            colliders[a].physicsImpostor = new BABYLON.PhysicsImpostor( colliders[a], BABYLON.PhysicsImpostor.BoxImpostor, { mass : 0, friction : 1, restitution : 0 }, scene);
            colliders[a].checkCollisions = true;
        }

By default camera always look at center of ball 

(if we disable - make ball static..

 //playBall.checkCollisions = true;
//playBall.physicsImpostor = new BABYLON.PhysicsImpostor( playBall, BABYLON.PhysicsImpostor.SphereImpostor, { mass : 5, friction : 1, restitution : 0 }, scene); // 0.597=metal ball

we can see that perplexus mesh and box colliders are rotating OK ) (rendering is ok but physics is not ok)

I THINK THE MAIN PROBLEM IS THAT colliders(box impostors) ARE NOT WOKING WITH PHYSICS WHEN WE PARENTING...

Is there any way to DEBUG or TO SEE what is going on with box colliders/BoxImpostors of each colliders[]?

It will be nice if Debug-er will have option to turn on/off  to see what is going on with each meshes impostor.
 

--------------------
RaananW, I can't remove this two functions and make playground simpler. This two function take care to rotate perplexus around current ball position. Very complicated/magic functions :)

function RotateAround(transform, center, axis, angle) 

function RotateVector3ByQuaternion(vector, quaternion)

and I can't remove loading model and key listeners

 

Link to comment
Share on other sites

I add function for debugging physics (as you show us how to debug).


http://www.babylonjs-playground.com/#CKEHJ#1

 

I add FOR DEBUGING - HERE WE CAN SEE BOX IMPOSTORs of colliders[] are not rotating - hey are static!

function PhysicsImposterViewer(physicsPlugin, scene) 

PhysicsImposterViewer.prototype.update = function ()

var bodyViewer = new PhysicsImposterViewer(physicsPlugin, scene);
        engine.runRenderLoop(function() {                    
            if (scene) {
                scene.render();
                bodyViewer.update();
                poskrbiZaRotacijo();
                
            }
        }); 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...