Jump to content

Magnetic collection for collect coin


syed samoon
 Share

Recommended Posts

Hi SS!  Ooooh, excellent challenge! 

Here's a little video of what is needed... https://www.youtube.com/watch?v=fRLQSlh0qWA

Perhaps a 2-step thing:

#1 - Detecting when coin is near-enough... to be affected by the magnetic field.
#2 - Animating/flying the coin to/toward the constantly-moving player/magnetic-field center.

For #1:  Putting an invisible sphere around the player... which represents the size of the magnetic field... could be used with intersectsMesh() function, I suppose.  (detection of coin within magnetic field influence area).

For #2:  I have no idea.  Using the standard BJS animation system to move the coin TO a moving target (the magnet)... will likely not work.  After coin -> magneticField intersection occurs, the coin will likely need to continuously do player.position.subtract(coin.position).  This math (or its .negate()/inverse), should provide a FRESH coin direction-to-player... every frame (or faster). 

How to get the coin to move in the direction-to-player (a little bit) for EACH render frame... is a challenge.

Let's listen to others' ideas, now.  My synopsis/methods might not be the best way.   So, let's ask for better ways, and/or perhaps someone will "flesh out" my idea, and try some test scenes.

We could use this test scene... to do experiments with "coin sucking"  :D  https://playground.babylonjs.com/#36UHXZ#13 

Caution:  Each coin is currently parented to ground (might be important-to-know... for testers).  Party on!

Link to comment
Share on other sites

Hi guys.

Wouldn't player.position.subtract(coin.position) be much faster than ray-casting?

And aWeirdo's set-coin.parent-to-player... immediately, would be important, too, I think.  Otherwise, the player could be moving forward SO FAST, that he out-runs the animation/velocity steps, and the coin would get (slowly) left behind.  Player's speed out-runs the coin's catch-up speed.  :)

I think the position subtraction thing... gets you BOTH needed values.  You get a direction to/from the coin/player, AND a magnitude (magnitude == distance), right?

Maybe.  Lots of Wingnut 'speculation' happening, here.  :) 

Link to comment
Share on other sites

Yep, I think so, aW.  But parenting could be a problem IF user wants to incorporate physics.  Why put physics on the coins?  *shrug*  I dunno.

If someone can steer me into converting vec3 magnitude... into a single distance float, then I'll try an updated/new demo.

Thoughts?  Smart coins?  Put a beforeRender on each coin... and make them constantly "watch" if/not they are within the mag-field distance threshold?

If so, dispose it, for now?  Yeah.  A crap-load of coins, constantly measuring their distance/direction-to-player.  :)

Probably smarter to use scene.beforeRender and iterate thru the collection of coins, eh?  *nod*. 

I have a tendency towards autonomous "smart mesh" robots/mesh-behaviors.  Not sure WHY I have that tendency.

Link to comment
Share on other sites

well,
a registerBeforeRender on mesh is just another function being executed during babylon's loop i think,
so a single loop,


might be better than to have two loops (babylon loop) and loop inside scene.registerBeforeRender.. 

just a optimization issue i suppose so not very important atm :P 

edit; just quickly checked up on it, and it's an observer, so when beforeRender is being processed notifyObservers runs a new loop. so still two loops. 
 

anyway, distance.

// Returns the distance (float)
var dist = BABYLON.Vector3.Distance(vector3_a, vector3_b);

 

Link to comment
Share on other sites

Hey, thx aW!  Nice.

https://playground.babylonjs.com/#36UHXZ#14

Line 58 sets magnetic field radius, which is used to show the temporary magnetic field "proxy ellipsoid"  (woah, dirty talk, eh?)

The super dooper looper pooper is in lines 126-134... coded in Genuine Wingnut Slop-Code.  :)

Works gooooood.  Who's doing the coin animating, and the little fuzzy particle-puff of success? 

I can't do that part, cuz.. unions... ya know?  heh

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