Jump to content

fireball registerOnPhysicsCollide with ground


Recommended Posts

Hello world, this is my first post (and first weekend using babylon) so please be kind ;) First I'd like to say that BJS is amazing, and I can't believe I've gotten this far as someone with little programming background.

Here is a playground that shows the issue I'm having: http://www.babylonjs-playground.com/#DR6N9#15

The player (box) is able to throw fireballs, via spacebar. Movement is WASD. The code is supposed to detect collision of the fireball instance with the ground, dispose the fireball instance, and create a new different instance of the fireball being lodged in the ground. And then dispose that.

This does happen occasionally, but only when the player is facing x or z directions. (On my localhost I dont have the direction issue?) The rest of the time the fireball keeps bouncing along. In both my localhost and the playground, the lodged fireball instance often appears mysteriously floating in the air instead of in the ground.

I can't figure out if this is a physics engine issue or an issue with my code (most likely ;) ). Any insight would be greatly appreciated. Thanks!

Link to comment
Share on other sites

  • davidnl changed the title to fireball registerOnPhysicsCollide with ground

Hi @davidnl, welcome to the BJS forum.  I don't think you are doing anything wrong.  I did some tests.


I changed many things.  Made the scene larger, moved camera to front, increased ball size, wireframed it, and I disable MOST of collide func except...  a ball color changer.

So, same deal, spacebar to fire, ball is higher and shorter (more like cannonball than bullet) (I wanted to try to increase ball-ground gravitational impact and also play with ball.ellipsoid)

I learned almost nothing.  As you can see, our line 126 registerOnPhysicsCollide ... is only triggering SOMETIMES.  And it NEVER wants to trigger on the first impact, which is where YOU want it to trigger. (to change-out ball, and cause dirt particles blast, play sound, shake CSS canvas.marginTop... you know... all the GOOD STUFF)   :)

We've seen this before... in a paddleball/ping-pong game that a forum friend is building.  Inconsistent collide trigger events from the impostor.  Possibly related to the physics "step" speed, which I know very little about.  I would love to figure out what causes this. I will try to study it more.

Calling all helpers.  Issue open.  Sorry for inconvenience, D, and sorry for no solution... yet.

Link to comment
Share on other sites

Hi @Wingnut thank you so much for taking a look at this. I still haven't figured it out completely. It seems to inconsistently work with different browsers at different times on different devices.

I keep running across mention of .MoveWithCollisions, but I haven't really found a good explanation of how to use it. Could that be used instead of registerOnPhysicsCollide? Then I suppose I'd have to manually program the motion I want... but at least it might work more consistently until I can figure out the physics collisions?

Link to comment
Share on other sites

Yeah, that's a good plan.  Leave behind the physics engines and move to the BJS built-in intersect/collision system (where .moveWithCollisions() is used).  Do you need cannonball flight parabolas?  Maybe more straight-ahead shots with a little gravitational down-pull?  Either situation... is pretty easy, and you'll re-gain some scene-speed, I suspect.

Here's a cannon-firing demo from our friend Jerome... http://jerome.bousquie.fr/BJS/dev/artillery/artillery.html  WASD & left-shift to fire... for red guy.  Arrow keys and ENTER... for blue guy.  I THINK this demo even reduces the height of the heightMap... around the cannonball impact point.  (ground denting) :)  All in all, possibly some interesting code and parabola work... from a fine coder and thinker.

A playground search or forum search for 'shots', 'bullets', 'missiles', intersectsMesh, moveWithCollisions, etc... might pay dividends.  Stay in touch, good luck.

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