Jump to content

[solved] Player want to stand/move on moving box


Recommended Posts


hmmm... it seems friction is not working, Oimo or Cannon.  I got friction 250 set for both red and green, and mass 5 on green.

I think somebody spilled Teflon on our physics impostors.  They are slippery.  :)  I'll keep studying.  Perhaps others have ideas.  But I think your scene code is proper. 

Physics engines - perhaps not so proper.  :) 

I'm also seeing e.physicsBody is null error when impulsing the green box with the cursor keys.  This could be related.

Calling all helpers!  Be on the look-out for a leaking Teflon truck... causing our frictions to lose sticktions.  (Wingnut hides his fingernail files and floor mats.)

Link to comment
Share on other sites


See-saw.  :)  That's a .05 friction on both impostors... with .2 mass on green.  hmm.

Maybe you and I don't quite understand friction, huh?  *scratch scratch*  I would have thought that the green box should stay atop the red platform... (in your original demo) via friction. 

But... hmm.  Perhaps we have learning to do.  :)


The circular motion of the platform... is not a "physics motion", it seems.  Since the circular motion is done with sin/cos actions on the platform itself... there might be no circular motion on its physics body.  In the #5 demo, I see good "ramp angle" physics, but I see none of the sideways movement of the red platform... transferred to the green box.  It slides straight off the ramp.... per the ramp angle, but it ignores all sideways movement of the red ramp.

It seems like we are missing an updatePhysicsBodyPosition() or something... just after the platform position setting... http://playground.babylonjs.com/#15AFCG#6   ...but no.  hmm.  Darn.

I bet... if we set the green box atop the red platform... then used applyImpulse (or setLinearVelocity) on the red platform... then I bet the green box would go along for the ride.  I just bet so.


Look at the console.  in line 100, I am printing-out platform.physicsImpostor.getLinearVelocity().  It's reporting 0,0,0... cuz... hmm.  The red platform needs to be moved with applyImpulse.  The .position adjuster in the render loop... is not moving the impostor WITH the mesh.  hmm.  Interesting.

Link to comment
Share on other sites

I think i understand now (more) :D

In my first scenario the platform 'teleports' from position to position. So the player has no chance to stick on. The player is unable to stick on teleporting objects i guess :lol:

I tried to move the platform also with impuls. This works better. But i this is still not what i want. the player slips too much on the platform :unsure:

Here my new test: http://playground.babylonjs.com/#15AFCG#8

you can control the platform with the keys: i,j,k,l

I found out the range of friction and restitution goes from 0 to 1. So 1 is max. correct me if i`m wrong :)

Bad for this solution is also: how can i move a object with impuls to the exact coordinates??

Link to comment
Share on other sites

:D  I like your personality and wit.  You are funny.  And... yes... you are correct, so far.  It is VERY difficult to impulse to exact coordinates (essentially impossible without brute force).

You are likely correct about 0-1 values - thanks for that info.

I write tutorials, sometimes (even in the forum).  MANY times, I am DESPERATE for a term... to use for... "a value 0-1 inclusive".  There's been huge discussions on the web... trying to determine a proper term for that.  Strange, just like this issue.  :D 

It looks like UnitInterval is the most-proper term.  If I use that term in a tutorial, everyone will say "What the hell is a UnitInterval?"  :) I think I have seen others call it a "normalized value", too.  (equally tutorial-unfriendly)

I've sent a message to the VERY busy BJS superstar named RaananW... asking if he would give us some advice.  SO... maybe we have help coming.  Others may comment, too, of course.  And, we can do more tests, yet.  Thanks for sharing your testing results, Hans!  Nice of you.  I have briefed RaananW a bit... on the issue. 

Physics bodies have .position, too.  POSSIBLY, we might make our own updatePhysicsBodyPosition... by continuously setting redbox.physicsImpostor.position = new CANNON.Vec3(redbox.position.x, redbox.position.y, redbox.position.z)... in the renderLoop.  Scary and demented, huh?  Brute-force positioning of an impostor... against every physics rule in the book. :)

Something to play-with, perhaps.  Wear your hard hat and steel-toed boots, okay?  :)

UPDATE:  Raanan agreed about the need to move red platform... using a physics motion method (impulse or setLinearVelocity).  He also mentioned that he MIGHT have another playground for us... later.  But... we need to find a work-around.  We can't load cargo containers onto our ship, and then the ship sails away from the dock, and the cargo falls into the water.  :D  (nah, we would impulse the ship away from the docks, right?) 

Is this for a conveyor belt system?  Rollercoaster?  hmm.  This sort of sucks.  It is almost like we need to build invisible "guides" under the platform, then impulse the platform on one axis, and the slot/groove invisible "track" beneath the red platform... "steers" it around.  hmm.

Link to comment
Share on other sites

I like to discussion with you too :) Its super nice to have someone who understands my words because … sometimes I don’t understand them too.

I think there is no problem with difficult terms in tutorials. There is just a problem with the attitude of the learner :D

Thanks for your help and feedback. I feeling me picked up. And thanks for ignore my bad English. I´m from Germany and try my best ;) 

Of course, I share my experience with you. Together we are more than the sum of its parts, right? :)

I also thought about linearVelocity. The Problem with this is, if i am right: the movement of the object is just in one direction, depending of a given vector. A movement in a circle is so not possible. OR? I hope I´m wrong here :D

Another big problem: If the platform starts to fly respectively y-axis rise, the player will glitch into the platform and got a big collision impulse. I hope the player has a parachute …
I think I forgot to implement the parachute :P

I don´t give up and continue my research. i will keep you informed ofcourse.

By the way. I have also another Question/problem. It is about how to create local gravity respectively gravity fields. I think it is better to create a new topic for this later. But, one by one :X

Link to comment
Share on other sites

haha.  You are a nut!  :)

You are correct.  linearVelocity or applyImpulse... both are very difficult to make circular/orbital path.  BUT... physics engines have hinge joints and distance joints, and motors to spin those joints.  Think about that, if you please.  Here's my stupid train wheel demo.  It uses all "hinge" joints (and no motors), but for your red platform, perhaps use a "distance joint".  (a hinge joint with distance allowed between physics bodies) 

Click on-screen to impulse the train wheel.  Wobble wobble.

If you searched our playground database... for things like 'physicsJoint' and 'distanceJoint', you could see how to use them... and do tests.

You know what I am thinking?  Put mesh (perhaps sphere) in middle (0,0,0).  Set .visibility = 0.  Set physics sphere impostor on it - no mass.  It is a central pivot point.  Es ist der zentrale Anker für das Karussell.  :) 

Use distance joint between center sphere and red platform.  Apply impulse to red platform, and it SHOULD spin around.  Joints are fun.  Addictive to play-with.  Remember to eat and sleep sometimes.  :)

Link to comment
Share on other sites

I like how you think! :)

The problem is: This works with the circular path problem, I bet. But the player wants to stand/move of a platform which is controlled by himself or by me with a fixed (super complex) route. The platform can be a boat, space ship, hovercraft and so on. So, the path will be more complex. And the player is able to jumping on/from the platform. In your tests, we see the friction is working, but the platform/wheel is always rotating. For moving objects from position to position it doesn`t working, I guess. ^_^

I have another idea. It will take some time. I will try it and inform you. B)

Maybe we can also watch into the rotating function implementation. Why is fraction working here? Is there an update function we are looking for? :wacko:

Link to comment
Share on other sites

Thanks! :)

An update:

I tested to move the platform with impulses. It works, but the problem here is: the player needs high mass and friction. This is bad, because my player is moving also with impulses. The impulses for moving a fat heavy player is also very very big. The moving calculations for the will become bigger than they should. And can you imagine how other object react with (the collision of the) player? :D

Link to comment
Share on other sites


I adjusted Han's latest.  I removed some friction between ground and platform, and increase friction between platform and player.  I also added mass to player.  (Some of the same things Hans told about... with his latest tests.)  Works pretty nice. 


(I-J-K-L to thrust platform)

I'm still getting some console errors.  Not sure why.

All in all, general issues are...

1.  How to make a physics-active object... change positions precisely? (how to accurately follow a path3d?)

2.  How to make a physics-active object... change rotations precisely?  (almost SURELY a Quaternion-based thing)

Hans... yeah... mass/friction/thrust values... might need "live" adjusting within game/sim.  This is normal.  Fat players with good shoes, skinny players with bad shoes... we see these problems every day here in snow/ice areas.  :)

Platform thrusts should start gentle, so player doesn't slide.   This is often done by using TINY impulses, but allow keypress/impulse repeating when key is held down.  (might be already repeating when held).  Then, these little impulses are additive/cumulative.  *shrug*

Let's first get platform physics body... following a path of points (get platform impostor moving under its own power).  Then we can do more green box drops, and see if player can hang-on.  :)  Again, making an impostor follow a path... is against its nature... but we still need it, and so do other game programmers.  I hope @RaananW or others have some ideas.  I can't think of any, yet... other than... computer-assisted impulsings/velocities (computer constantly monitors deviation from preferred trajectory, and adjusts with tiny impulsings... much like the international space station and other spacecraft.)

Link to comment
Share on other sites

This works ... wait .... if I move the player .... I move also the platform too :D  It's too sticky.

If the platform turns relative sharply into another direction or is stopping immediately the player will also fall down. So, this need also the additive/subtractive impulses. I think we get closer to the solution :) 

Link to comment
Share on other sites

:)  Our player is sitting, and being pushed by thrust.  That will move the platform, too.  Player should actually "walk" on platform.  Change player to green sphere and sphere impostor.  Or, perhaps, time to make a "rag doll" jointed-together stick-man... with box impostors on feet.  Thus each foot-box UPward and tiny bit forward... to simulate foot step.  This will minimize platform being affected by player movements.  Lots of work to make rag doll.  Here is a demo.  http://www.visualiser.fr/Babylon/character/default.htm  (press G, then repeated press F)  (x30 is fun, too)

With sphere impostor for player, thrusting the player... will not move the platform.  Sphere impostors have no friction against flat surface.  Not enough surface area on bottom of sphere.  (Fenomas taught me that.)  :)

BUT... you know... drop the green sphere on moving platform, and it will roll-off and fall, immediately.  So, still challenges.  :)  FUN, though, huh?

Link to comment
Share on other sites

Not bad! 

I wish we had more physics "custodians" and helpers... than we do.  It seems that the forum sort-of dumped the load on @RaananW, and he's pretty swamped in real life.

Have you seen references to "sleeping" as you wandered-around in physics engine land?  Sleeping is to prevent something called "Brownian jitter" (that's one name for it).  I believe your green box is slowly "jittering" (vibrating) off the red platform... because... the green box never goes to sleep.  (keep in mind that the box would exit sleep mode... when an impulse is seen)

I've raised this issue numerous times, and have even done some tests.  As far as I can tell, none of our impostors in either 3rd party engine... ever sleeps.

Nobody ever pursues the issue, and it's not Raanan's fault AT ALL.  It's a lack of giving a shit.  Pinging Raanan every time there is a physics engine/plugins issue... gets us nowhere.  It's just a hand-washing... a passing-the-buck... an attempt at "delegating".  Raanan is a super nice guy, and great helper... but he never signed-up to be the lone custodian of the physics engine and physics plugins classes.  (Can you tell I'm using this post as an extension to the "BJS is moving fast" thread?)  :)

Yep, one thing is moving fast, for sure.  The jitter on your green box.

It seems that someone is working on the playground searcher, this morning (it currently doesn't work... a potential good sign).  (another issue I raised in the 'moving fast' thread).  Hooray!  Maybe my words aren't COMPLETELY falling on deaf ears.  :)  I was going to show you my .is_sleeping testing playground.

Hans... take a look here... the Cannon docs for 'body'... http://schteppe.github.io/cannon.js/docs/classes/Body.html  (scroll to page bottom to see properties and methods).  You might want to drop the green box on the ground, while render-loop-monitoring body.sleepState... do some experiments.  See if you can get ANY Cannon body to go into sleep mode.  Last I tested, you can't.  Be sure to take into account the other related properties/methods... sleepTick, sleepSpeedLimit, sleepTimeLimit, etc.  I'm not sure if there are things to learn, there.  It's certainly not fun troublshooting/testing.  I doubt that you wanted to "go deep" on the physics engines, or BJS PhysicsEngine class, or BJS CannonPlugin class... but... if you CAN find an issue there... you will not only help your own physics projects, but you will have done a great deed for Team BJS.

Aside: Did you see that there are TWO types of impulse, there?  ApplyImpulse and applyLocalImpulse.  I wonder if applyLocalImpulse would ONLY impulse the green box but NOT transfer that thrust to the red platform.  hmm.  :)

I suppose I should try to run-with this jitter issue/problem... soon.  If you would like to do some tests and give us a little report on what you find, that would be great.  I think... if we can get green box to sleep... (preferably automatically, without forcing it to sleep)... then the "vibrate-off" problem would go away, and perhaps even our friction would work better (but maybe no change to friction, because it is a phenomena used on MOVING bodies... not sleeping ones.)

We had a chap here about 8 months ago... building an automated warehouse.  He was moving freight around on a robotic elevator... future plans for picking, stacking, it was cool.  But his freight kept vibrating off-of the elevator lift... because of jitter.  I brought a camera real close... where we could actually see the jitter.  Then I pointed it out again, and one more time, and NOBODY took interest in the issue.  I might as well have been talking to a rock.  I think the guy got discouraged and then started beating his wife, kids, and pets.  :D

Things like this... discourage me, too.  It makes me accidentally say things like "Hey, if nobody else gives a shit, why should I?"... and that's not who I want to be.  But if I remember right, there were a few who gave a shit enough to do "pinging Raanan"... but... he coded the entire "new" physics engine interfaces... no small task.  In doing that, he unwittingly became the custodian of the physics engines and their interfaces... and he just doesn't have enough time in his life... to handle all the physics questions.  ALL of us need to help him... including me.

Sigh.  Sorry for the venting, Hans and other readers.  Raanan has gone well-beyond the call of duty.  Others... I don't know if they give a crap about the jitter and about Raanan's sanity.  It seems I see a lot of "blowing it off".  We've had over a year to build a test suite for our physics engine and plugin classes.  Is anyone working on it?  Nah.  :)


Link to comment
Share on other sites


I put a renderLoop-based console.log(player.physicsImpostor._physicsBody.sleepState); at line 101.  Stuck at 0.  yuh, yuh, yuh.  No sleepy-poo.  player.physicsImpostor._physicsBody.allowSleep is true.  hmm.

But, perhaps there's things I don't understand... about body sleeping.  I'm going web reading. :)

Link to comment
Share on other sites

You are right!

In my last test the player moves still from the platform. It is moving slow, but it does. Its because the jittering, i think. I am a perfectionist. So, i have to figure out why it is not perfect! :)
I will try to put the player/green_box to bed ;)


I Understand the stuff now a little bit. I got one ebject in sleep. ;)

The problem is the force called gravity! It pushing two objects together. They collide and the force pushes them again together and so on. How more mass an object has  the more jitter you can see. So, one solution is to reduce the force to zero. The object can sleep because no force keeps it alive.

See (in console too): http://playground.babylonjs.com/#1Z17G7#27

The Problem can be solved if we can control the gravity. See my new topc btw. :D


Instead to controll the gravity we can also control the mass:


If the mass is zero no force will influence the object ... it can sleep.

New Problem:

I found out another problem: http://playground.babylonjs.com/#15AFCG#12
All works with the platform on the ground. If the platform moving in the air (platfrom.y > ground.y) the player changing the rotation of the platform :blink:

Link to comment
Share on other sites

Nice testings!  Well done!  Interesting!  I need thinking time.  Keep going and talking, if you like.  You have done much discovering, here.  Cool!

Gravity!  Why didn't I think of that?  :)  I wonder how low gravity must be... for auto-sleep.  Perhaps that depends upon mass.  hmm.

Link to comment
Share on other sites

Sorry for my downtime. I have also to study :rolleyes:

I will continue on it now. I have another problem:
The platform is now a boat. I want to add a railing.
The railing must have another color/texture.
How can i connect the objects and every connected object has its own color/texture? :)

I tried following:

  • object.parent:
    •  dont work right with physics
    • dont work with multiple objects
  • BABYLON.Mesh.MergeMeshes:
    • all objects got one texture/color
    • physics goes strange
  • object.position = platform.position:
    • works fine but i can not change the object position relativ to the platform

Here is the example code:

Link to comment
Share on other sites

Hi Hans.  Me too - delayed.  I caught a head-cold from hell... erf.   Someday you and I will study the physics of mucous.  (or not)  :)  Pretty cool of you to honor the Chinese New Year, too!

There is one method that you did not list, though.  JOINTing the railing to the platform.   (Also, you can disable line 17-18, too.  Those are used for BJS built-in collisions, and not for 3rd party physics engines like Cannon and Oimo.)  But, let's leave joints out of the picture... and check parenting again.

In the earlier-mention wheel demo, parenting DOES work correctly with physics... because the green rod is parented to the wheel.  The wheel and green rod ARE working properly AS IF they were a compound impostor.  Physics forces/energies are passing bi-directionally between white wheel hub... and red block, and they are passing realistically.

SO... I think your deductions are premature.  You need more tests.  Let's start with a fresher playground, using less scaling and more meshBUILDER things, and make sure we have good parenting.


Parented railings looking better there, yes?  Better physics?  Keep experimenting.

Link to comment
Share on other sites

@Wingnut you are right here :D I think i did something wrong with the parent property. I will try it again ASAP.

Head-cold ... i know what you mean :rolleyes:  I can celebrate the chinese new year, beacause my wife is chinese :) So i feel with it.

I have also an idea to keep the platform right in the air. More here later. ;)

A question: How can i get the option values like width, height and depth from the object created by meshbuilder?


Link to comment
Share on other sites

Ohhh... you want to do some "live" railing-scaling, huh?  :) (change the sizes AFTER construction).

Yep, we will need to return to .scaling for that.  There are no .width, .height, or .depth properties to adjust... post-construction.  They are constructor "parameters" only. 

There is way to measure the sizes of mesh, and I included a test at lines 84-87 in the demo below... to show how.  It is not for SETTING.  Only for GETTING.  Lines 84-87 are reporting BAD DATA, in my opinion.  The bounding info is not showing the scaling changes done to railing01.  Perhaps my railing01._updateBoundingInfo();  (line 65) is not working.

I decided to re-insert your/some scaling code lines... http://playground.babylonjs.com/#2ACS0V#4

As you can see... we got trouble.  You were correct.  Scaling + parenting = physics problems.  

I tried some ._updateBoundingInfo() in lines 65, 70, 75, 80 (after the scalings).  No joy. 

I don't know WHAT the green box is sitting-upon, but it jitters-off in a few minutes.  :)  Yay jitter.  heh

Railings not working well.  Cursors not working well.  ARRRGH!!  *sigh*

I did some looking in https://github.com/BabylonJS/Babylon.js/blob/master/src/Physics/babylon.physicsImpostor.ts

Nothing interesting found.  We do the railing-scaling BEFORE setting physics impostors.  So...  impostors SHOULD be constructed using scaled shape sizes (and all should work correctly.  But nooooo.)

I see no way to scale impostors, anyway.

SO many problems for you, Hans.  Sorry.  I will keep thinking, and perhaps we will get help from others, soon.

Link to comment
Share on other sites

Hi again.

Maybe it is time to start a new thread, Hans.  Perhaps use a "physics" keyword (to make it appear red at beginning of title).  

Title it... perhaps...  Issues with impostors on scaled shapes

It might be the only way we can get some more help.  Not sure.  Your call.   Big dogs tend to avoid long-running threads.  You and I (and any other folks) can still have conversations here, of course.

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.

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.


  • Recently Browsing   0 members

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