Jump to content

How to: Stop an impostor after a given time?


Recommended Posts

So i had a project that i used cannonjs and setLinearVelocity with setTimeout to set the linear velocity to 0 after a given time. However after many tries i kept getting different position changes. So i tried to simplify it and made a playground: https://www.babylonjs-playground.com/#BEFOO#232

What i realized was setLinearVelocity was very dependent on frames after couple runs where sometimes the impostor would even move only half the distance. Does anyone know a more reliable way to more impostors?

PS: I added an ss with positions before and after the movement.tests.thumb.png.cb993408c731e8733ed518fb54e804a4.png

Link to comment
Share on other sites

Hi again, Bacterion... errr... Batucrion.  ;)

   Um... aren't you really seeking a move distance


If ya have the previousPosition of the p-body... then... let's see... http://doc.babylonjs.com/api/classes/babylon.vector3#distance

(Careful using Cannon vec3 sometimes, and BJS vector3 sometimes.  Maybe no problem, but verify.)

Also, be careful with previousPosition, which MIGHT be the position at the LAST WORLD STEP.  You really need previous position of last isSleeping = true.

I always like to make things autonomous/automatic... so... I would add my own function to the Cannon physicsImpostor... or maybe on BJS PhysicsImpostor class... with its own interval timer.

The impostor itself would periodically check to see if it has a moved-distance from previous(Sleep)Position > 9.9. 

If so, linearDamping ON... full power.  :)  Send report to server... "I've initiated full braking and should be stopped soon."  Or... "I just went to sleep at position X Y Z."

(Be sure to set world allowSleeping or something similar.  Also watch out for continuous collision with ground... possibly preventing some of the MANY 'sleep' settings... from activating.)

Perhaps same system with collision messages.  "I've hit something after 4.5 units of moving.  Will report new position once I enter sleepState."  :)

Just an idea.  Not sure if any of it... would work.  Stay tuned for more comments.

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