tentone / nunuStudio

Web powered cross-platform 3D, WebXR game engine.
https://nunustudio.org
MIT License
2.12k stars 317 forks source link

Drop ball inside transparent container with real physics #77

Closed pkill37 closed 7 years ago

pkill37 commented 7 years ago

I am making a small program where the goal is to drag and drop balls into the container according to the title's instructions.

image

It's mostly done, I just need to figure out how to make it behave with real physics once the ball is dropped (triggering a function). Specifically:

I've read the physics tutorial but it's very basic. I understand you're using Cannon.js, but can you give some more pointers on how I can achieve my goal? How easy is it?

tentone commented 7 years ago

Hi

For this i would create a physics container using boxes and have the balls as spheres, all of the physics elements should be locked programatically in the Z axis (by forcing the Z velocity to 0 and position to a defined value).

To identify if the ball is inside the JAR you can use 2D formula to check if "circle" if inside the "rectangle", that is probably the easier way.

Im planning on doing small platformer tutorial soon that will explai how to do some of these things.

You can check the demo i currently have here, https://nunustudio.org/examples/demo.html?isp=files/platformer.nsp

I hope this helps