Jump to content

Rotation and Physics Issue


ramsestom
 Share

Recommended Posts

I have a scene with physics where I need to rotate some objects in the WORLD space. However, the physics do not seems to be updated after the rotation. I made an example to show the issue:

http://www.babylonjs-playground.com/#1MLACF#0

At start, the ball is well affected by gravity and fall on the box. But then, if I rotate the two objects with mouse so that the ball is now on one side of the box or bellow it, the ball do not move (it should be attracted by gravity to the bottom of the screen when the box surface do not block it...)

So how can I update physics on rotated objects?

Link to comment
Share on other sites

http://www.babylonjs-playground.com/#1MLACF#3

Hi R.  I'm sure what you are using sbm for, but I disabled it.  No parent on sphere... he needs to move free.  Now I rotate box, not sbm.  Ball is active now, eh?  :)

Hope this helps.  Here is another simple Oimo physics playground... if you're bored. Click on canvas, hit/hold any key. 

Link to comment
Share on other sites

Hi. I am actually using sbm to group sphere and box. Because here this is only a simple example but actually, in the game I am trying to create, there would be some balls inside cubes and the user should be able to rotate all the objects of the scene at once (imagine he has a cube with a ball inside and he want to rotate it in front of him like he would do with a real cube by changing the face he is looking at. If the ball is at the "top-left-front" corner of the cube and the user rotate the cube on the y axis so that he now has the side of the cube that was left in front of him, I want the ball to appear on the "top-right-front" corner). 

I can achieve this by rotating cube + sphere like this:

http://www.babylonjs-playground.com/#1MLACF#4

But when you have multiple meshes that you need to rotate, this is kind of a mess. That is the reason why I would have like to be able to group meshes and rotate them all at once without messing with the physics...

 

Link to comment
Share on other sites

Ok, I think I understand, thanks.

You DO want to use physics, right?  If you put the sphere in group that isn't affected by gravity, then the ball will not drop or roll.  It will hold position WITH sbm.

In your example, with physics ON, ball will not stay in top left corner.  It will fall immediately to the bottom left corner.

Let's say a single ball is bouncing inside the box... un-parented (it has to be, in order to bounce around, unless its parent is bouncing along with it).  Let's use that CannonJS meshImposter example for a moment... http://www.babylonjs-playground.com/#1FXRWT#13

Ball starts in top-left-front, but immediate ball drop... not parented to anything.  To keep ball in top-left-front, then rotate the box right (making ball in top-right-front), you almost HAVE TO turn-off the physics.

Or do you need physics at all? :)  I am confused, aren't I?   Sorry.  Leaving ball be physics-free to bounce and roll... versus parenting ball to something which would kill its physics movements.  If the ball is bouncing, and the box is rotated 90 degrees right, and the ball keeps bouncing "correctly" during and after the box rotation, would that be a success?

*scratch scratch*  (I'm easily confused, sorry).  I will do some more testing... see if parenting ... stops ball physics movement.  I think it does.  But your ball DID do a drop at scene-run time, even though it was parented.  hmm.  Maybe I am wrong about parenting stopping physics motion.

Link to comment
Share on other sites

Hi again.  Ok, I was wrong, parenting does not kill ball motion.  hmm, I learn something every day.  :)

But... check this out... http://www.babylonjs-playground.com/#1FXRWT#14

sbm creation at line 33, ball.parent  = sbm at line 34, but line 35 is no-go.  Activate line 35, and the ball falls thru the meshImposter box.  Hmm.

Oimo has no meshImposter option, so an Oimo-legal box... would be 6 planes or box flat-panels... assembled into a box shape.  All other attempts to put a sphere inside of an Oimo box imposter... fail... even when the box is created with BACKSIDE or DOUBLESIDE mode.  Darn.  A failed attempt:

http://www.babylonjs-playground.com/#1MLACF#5

Sphere.position.y = 0.  Now the Oimo b-imposter fires the sphere out-of the box.  We can't use a standard box with Oimo.  We need a box of walls.  :)  Here is a box of walls, (labeled // playground), that is used for the physics demo on the BJS main website.  It is an Oimo-based demo, I believe.  :)  Sorry if I am not being helpful.

 

Link to comment
Share on other sites

Quote

Ball starts in top-left-front, but immediate ball drop... not parented to anything.  To keep ball in top-left-front, then rotate the box right (making ball in top-right-front), you almost HAVE TO turn-off the physics.

Yes I took a bad ball start position to explain (because in reality, my "box" containing balls is not empty, it is a 3D maze. Which is the reason why a ball can stay at a given position without necessarily falling ;) )

Anyway, lets keep it simple for the moment and lets consider a simple box containing a free ball like in the example you created. What I want to be able to achieve is to rotate the box (like you would do with a real box that you rotate between your hands irl) and to have the ball inside the box correctly affected by the world gravity after this box rotation (I realized that I just had to rotate the box and let the ball free to mimic reality so no more grouping needed)

I made a sample from yours: 

http://www.babylonjs-playground.com/#1FXRWT#15

If you rotate the box with the mouse, you will see that the ball movements is inconsistent with real physics... So there is an issue

 

Quote

Oimo has no meshImposter option, so an Oimo-legal box... would be 6 planes or box flat-panels... assembled into a box shape.  All other attempts to put a sphere inside of an Oimo box imposter... fail... even when the box is created with BACKSIDE or DOUBLESIDE mode.  Darn.  A failed attempt:

Yes I know that, I already have my box defined as 6 planes on which I apply 6 Planes impostors in my real code (in Haxe. I only use javascript version of babylonjs to debug and have help on the forum ;) ). No big deal.

Link to comment
Share on other sites

Hi again.  http://www.babylonjs-playground.com/#1FXRWT#17

I turned on a little ball roll (friction and restitution) (friction does nothing on spheres, though, because of no significant contact area).

To be frank, I don't see the inconsistent ball movements.  Okay, okay, when the ball goes thru the box walls, that's certainly not sane.  But other than that... it looks... pretty good.  Maybe.  Maybe I'm not inspecting properly, though.  I'm a bit distracted at the moment, but I wanted to visit the topic again... see what's shakin' here.  :)  Thanks for the comments and explanations.  Hopefully others will comment.

A note for testers... there is a type of vertical drag active here in Ram's demos.  Drag up/down is active.  That's when it is easy to send the ball through the box walls... gone until reRUN.

Link to comment
Share on other sites

What I found inconsistent is that if you rotate the cube 1/8 by sliding vertically once with the mouse, the ball fall inside bottom corner of the box (till then, everything ok) but the next 1/8 horizontal rotation (by sliding vertically once more with the mouse), the ball start jumping up (whereas it should just roll on the bottom face of the box). 

I don't know maybe this only requiere some tuning of ball elasticity and friction but it still seems an unnatural behavior to me.

And the fact that the ball can escape the box when you turn it multiple times also shows that the system certainly has issues ;)

Anyway I made a sample with the camera centered on the z axis (which render the understanding of what happen easier as gravity and bottom of the screen match perfectly)  

http://www.babylonjs-playground.com/#1FXRWT#18

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

Well, it is interesting you got internal collisions to work :) 

Putting an object INSIDE another object might work and might now. Try changing the engine to Oimo and you will see that the box "spits" the ball out. 

To get internal collision working properly, you will have to create 6 walls and add collidors to each and every one of them. Then, rotate them together (or using a parent).

The reason the balls falls out (or escapes) from time to time is because you are turning the box too much in each step. Turning 45 degrees on each step might make the engine think that the ball is suddenly outside of the box (which, evidently, does happen). The ball will then simple fall out. Maybe add a "pointermove" event that changes the rotation in smaller steps.

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...