so if I have an object that has a collision listener on it for the Cannon Physics plugin.
When the event triggers and I get the return from the event of the (boundObject, contactObject ) how do I get the contact point?
Adding @trevordev
Hi guys. P8, did you do a good web search?
https://github.com/schteppe/cannon.js/issues/216
https://github.com/schteppe/cannon.js/issues/118
A bit here, too… Collisions -- how do I tell what faces of each colliding body intersected? · Issue #43 · donmccurdy/aframe-physics-system · GitHub
Cannon’s contactGenerator got renamed to narrowPhase… Narrowphase - cannon
Somewhere in there, Schteppe talks about narrowPhase/contact objects only having worldspace contact coordinates, but he talks about using a raycast (some are built-into Cannon already)… that can be projected from either collided object… toward worldspace collide coords… and that will return which “faces” collided.
It sort of looks-like Cannon “world” has a .contacts array… but finding YOUR wanted contactEquation… among the array… not sure how that is done.
Can you build us a little testing PG? https://playground.babylonjs.com/#R8ZH46#6 might work as a starter.
Ok, that’s all I have found, so far. Stay tuned… better knowledge likely forthcoming, and teach us what you learn/discover, thx.
Hmm, that might work Wingnut! Most of my collisions are aabb, and its between a sphere and a box for the most part, so I guess I could just do colliders position - target position which gets a direction. I then guess I scale it by the distance - radius of the target sphere to get the contact point.
I was hoping for like a quick collision.contactPoint or something but I guess Ill just have to code something up.
hahah your test scene is wild!
I cleaned it up a little and noticed it keeps dropping an error about the physics is not initialized?
https://playground.babylonjs.com/#R8ZH46#7
This scene is really buggy… it says the physics are not initialized while they are and then it drops an error saying there is no oncollision function while at the same time firing it…
super weird, maybe we should just do another example scene?
Yea, unfortunately the info you are trying to retrieve is not currently exposed by Babylon so the links Wingnut provided are probably the best path to getting that internal info but calculating it yourself as suggested is probably the easiest way to get it working.
Yeah, I should have found a better testing PG than that. Not sure what causes those errors… I have them, too. Maybe it involves the timed impostor disposing for the cannon balls.
I’ll try to do a little more web-searching, too. P8… if you get a cleaner test PG with PE-triggered onCollide working good… make sure you share the URL with us. This is an interesting area of study, and it is the first steps in producing realistic manual-emitcount “spark-particles” when p-bodies collide… something not yet invented… by our people in the “Demented Inventions Dept”.
I think this is important… for disposing one or both or many shapes/impostors… upon impact, too. Fist bump with “blow it up” feature added.
There’s also a rumor… that when you set the “fertility flag” = true, two physics bodies will produce a new “offSpringImpostor” and shape, upon gentle collide. Just like the band with the same name, rolling stones can produce a serious “trail” of offspring shapes… as they roll across the plains/planes. heh.
Ahh, comedy… it’s a dirty job… but somebody has to do it.
https://www.babylonjs-playground.com/#4NCYQH
there is still some quirks going on here… hmmm what would cause the balls to take off on contact like that?
Rawr, why is cannon so unpredictable.
UPDATE
https://www.babylonjs-playground.com/#4NCYQH#2
Guess it helps if you kill the torque from the impulse. (even though there should not be any?) I guess my contact point is off?
https://www.babylonjs-playground.com/#4NCYQH#3
So I started really thinking about it, and once a collision happens I will need to do a secondary AABB calculation. First I need to grab the two shapes establish their bonding shapes and sizes then start projecting… Kinda sounds like its gonna be a hassle…
Other Options would be hacky response for everything.
There has to be a way to get the penetration displacement vector, cause how else would it step objects out by specific velocities I mean that’s how physics engines work o_O… so I need to find out a way to expose this variable to the onCollisionEvent I really really dont wanna do secondary AABB calcs.
Just found this:
Also I set the restitution on the bullets to 1 and the ground to 1 and am getting now bounce… whats up with that?
heh. spawnsparks.
Wingy screws-around… https://www.babylonjs-playground.com/#RYXIT#10
I’m seeing some good console output from lines 111-112. Not sure what it all means, yet, but the link in your previous post (local contact point) seems well-apropos. Nice find - helps our learning.
BTW… https://www.babylonjs-playground.com/#4NCYQH#8 You need to spell restitution correctly… for these picky PE’s.
wow full reeeee moment… I was looking at this on my breaks today and so that was a stupid slip.
Good amount of coding for like 15 mins though
Definitely. And darned fun to watch, too… I started laughing 2 seconds after the load finished. I was watching Archer the other day, and the term “spray’n’pray” was said… regarding a type of gun-shooting method used by noob spies/agents. I immediately thought of it… when i saw your Cannon cannon.
I’m glad someone picked up on that. (Ha, Ringo got it)
Does anyone understand what Schteppe is saying… " .ri and .rj are world-oriented vectors . So to get the local point you need to rotate them with the inverse of the corresponding body rotation. Or just use the approach I suggested above: add the body position to get the world point and then go local. I’d suggest computing the world point first to verify that you’re on the right track."
I got good ri and rj numbers showing-up at console… although I’m not sure if I can console-dump BOTH bodies yet. I think I should have id #14 and another id # viewable at console.
And, I don’t see any numbers that CHANGE at every collide. I tried dumping a few of the vec3-looking things… but they seemed to be the same… each impact. Maybe I don’t understand “the pool”.
Wingy a little confused… but… I’d really like to see the spawnsparks work in BOTH PG series. If we get contactPoint nailed… we get to play with that new power. I’m fine with stopping at good BJS worldSpace values… all that’s needed for sparks/dust. But your project needs point-of-collide in localspace for the shape, so you got more hell ahead.
You might need the faceId from the raycast … done at collide-time. That would be useful to momentarily change the shape’s face-color, or apply a char/scuff-mark texture at contactPoint.
“add the body position to get the world point”, says Schteppe. Let’s see… am I smart enough to do that? hmm.
https://www.babylonjs-playground.com/#RYXIT#11
Cleaned up lines 111-113. Those ri and rj console numbers never change. hmm. contactPointPool never gets longer than 1. hmm. It seems I’m repeatedly dumping values from the very FIRST contactObj… and then it goes stale and never updates itself.
But maybe… do as Schteppe says, and get body position(s), and add it to ri and rj, see what blows-up. Ok, let’s see… find body positions, do a native Cannon vec3 addition operation… erf. My brain is starting to hurt.
https://www.babylonjs-playground.com/#RYXIT#12
There they are!
https://www.babylonjs-playground.com/#4NCYQH#9
Yeeehaw.
SOLVED
https://www.babylonjs-playground.com/#4NCYQH#11
https://www.babylonjs-playground.com/#4NCYQH#12
^Shadows seem a little off still.
VERY COOL!!! YAY! (droooool) Nice work, P8 (and others)!