Jump to content

Stop body after collide with othe body


cpu_sam
 Share

Recommended Posts

Hello again people!

Well, I have a little problem with collisions in babylon with cannon js. For example: I move my player with translate, it's just a box with box impostor, and when I go and crash with another  box the player is  throw in the other sense, here it's all ok but the force with the player is throw it's very strong. I tried with resitution = 0 or friction = 1 but happens the same strong counter force.

So, can anyone help me?

Link to comment
Share on other sites

Hi again, Sam!

https://www.babylonjs-playground.com/#15AFCG#28

A little testing playground.  Cursor keys move the green box... slowly.

The translate command... moves a mesh REAL FAST.  Not always far, but fast... and with lots of physics force.

In this playground, I made line 72 power... real low/small.

Power is not the correct term.  We should name it "distance".

Let's imagine that a translate... happens at 1000 KPH speed, with 100000 newtons of force, because IT DOES.

Mass, friction, and restitution settings have little affect (or unexpected affect)... against a 1000 KPH 100000 newtons force, right?

Translate and rotate are not physics engine commands.  They are designed to move mesh, not impostors/p-mesh.

The BETTER way to move physics-active mesh (call them 'p-mesh' if you like)... is with applyImpulse, applyforce, setLinearVelocity, and setAngularVelocity.  Those methods are physics-engine-based movers, and therefore, they can be "counter-acted" by mass, friction, and restitution calculations.

Conversely, translate and rotate cares nothing about impostor counter-action/opposing forces.  Translate and rotate ignore calculations made by the physics engines.  They move distance or turn angles, no matter what.  After the translate or rotate finishes, the physics engine re-syncs the impostor to the new mesh position, then it discovers a positional overlap in two of its impostors, and goes counter-force crazy... trying to de-overlap the impostors.

So, I think.... applyImpulse, applyForce, setLinearVelocity... those are better ways to move a physics-active mesh (p-mesh).

And, in my opinion, it is very difficult to get good player control... using physics engine forces.  P-mesh tend to slide too far, tip over, do unwanted spin, it is just not easy.  It is because... with p-mesh... the physics engine is the boss of movements... not Sam's keypresses.  :)

Notice that there are few or none... "drive a player with physics forces" demos/playgrounds.  Why?  Because it is very difficult.  In a way, using p-forces (impulse/force/lin-velocity) is like BLOWING AIR on your p-mesh player.... to make it move.  Ever try to accurately-control/move an empty styro-foam cup... by blowing on it?  Almost impossible, eh?

Anyway, I THINK this is the heart of your problems.  I hope you understand.  Feel free to ask questions.  We can discuss/test keypress-repeat micro-impulsings or taper-up/taper-down setLinearVelocity systems, if you like. 

Be patient with yourself.  This is advanced stuff.  Do tests... think hard.  Use this playground to make edits, and more saves, more tests, and paste the URLs from those saves... here... and we will discuss them, if you wish.

Back on-subject:  To stop a moving p-mesh instantly... try things like this...

player.physicsImpostor.setLinearVelocity(BABYLON.Vector3.Zero());
player.physicsImpostor.setAngularVelocity(BABYLON.Vector3.Zero());

That should work, or something similar.  Physics impostors have an onCollide() function.  That might be a good place to put those "stop the p-mesh" commands above. 

BUT... keep in mind that player.physicsImpostor is constantly colliding with the ground... so... there might be problems testing-for collision... in this way. 

The "intersectsMesh" feature... as seen in http://playground.babylonjs.com/?10  - lines 68-73... might work for collide testing.  But, you will need to test for player intersecting with ANY collide-able objects in the scene (use for-loop, checking player collisions with all other collide-able mesh).  That sort-of sucks, eh?

I hope I have been helpful.  Not very much good news for Sam.  Sorry.  Others may comment soon, so stay tuned.  Party on!

Link to comment
Share on other sites

Hey Sam, I forgot to tell you something.  One of our users... said that it would be wise... to place an invisible p-mesh above the player, and attach a physics joint... possibly a lockJoint or a stiff springJoint... between the invisible mesh impostor... and the player impostor. 

Then, try your translate on the invisible mesh... and let the force travel down thru the joint... into the player p-mesh.

This way, there is a physics "isolator" (insulator?) between the powerful, fast translate force, and the ACTUAL player.

I have never tried this, but it MIGHT be worth testing.

Ok, bye again.  :)

Link to comment
Share on other sites

Thank you again Wingnut,  the real problem it's not the force of translate, because I had seen that translate it's very power full (even more than 9K!!! hehe) and I saw that it's not proper to my test.

I had change mesh.rotate() by impostor.setAngularVelocity and works fine, but change mesh.translate to impostor.setLinearVelocity and the same problem of before: the mesh move in the world axis, not in the local axis (that change with rotation). So, appears me that 3D it's not to play, but it's far very fun!

If you have some book, tutorial, or any think (free please) to show me, please, share it. I want to be good with 3D environments like I do with 2D

Maybe I just need something like collision detection and response "hard", like in general 2d world.

Link to comment
Share on other sites

https://www.babylonjs-playground.com/#15AFCG#30

I made a "drag-player-from-overhead-physics-joint" demo.  Arrow keys.

Works pretty good.  Interesting, at least.  :)

I could make a snow plow, bulldozer, or road-grader... out of this.  :o  heh  FUN!  We got motorEnabled, so we can tilt and angle the plow blade.  And we can just raise the Y of ibox (which is invisibleBox, in the end)... to lift the plow.  Just need to generate 2.5 million physics-active dirt clods, now, and we're in Tonka Truck Land!  Yay!  :)

Aside:  Are any of you guys seeing a one-line-scroll... of the PG app... when up/down arrowing?   Annoying, eh?  CSS issue, somewhere.

Update:  Url changed to #30... fixed an ibox z-position.

Another:  https://www.babylonjs-playground.com/#15AFCG#31  Line 141...  speed up Cannon timestep... 3 times faster.  I like fast physics engine.  :)

Link to comment
Share on other sites

if you're asking for the version of the physics engine Cannon - I think we are meant to stick with the one included with babylonJS distribution:
https://github.com/BabylonJS/Babylon.js/tree/master/dist
I think it's a modified cannon.js to work with the framework.  The newer versions I found on the internet I did not get working.

If you mean BabylonJS version for timestep, I don't think it was added until 3.0, but there were bug fixes for it in 3.1.

Link to comment
Share on other sites

It only depends on what clients you want to support what version YOU are using.  If you are using javascript then you can use babel to target ES5, because probably you want to use all the ES6 (ES2015) goodness when writing your app!  I even use ES7 decorators with babel and target es2015 when I use javascript.

If you're wondering about BabylonJS, it's written in typescript and compiled to target ES5 (from 2009), so it will support a wide variety of browsers:
https://github.com/BabylonJS/Babylon.js/blob/master/Tools/Gulp/gulpfile.js#L52

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