Batucrion Posted April 7, 2018 Share Posted April 7, 2018 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted April 9, 2018 Share Posted April 9, 2018 Hi again, Bacterion... errr... Batucrion. Um... aren't you really seeking a move distance? http://schteppe.github.io/cannon.js/docs/classes/Body.html#property_previousPosition 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. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted April 9, 2018 Share Posted April 9, 2018 https://www.babylonjs-playground.com/#BEFOO#233 After reading your problem more, it sounds like you want to move by set distance like wingnut mentioned. So i guess my PG is useless. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.