Hey everyone,
I’m new with BabylonJS and I’m trying to start from the basics to implement some fun ideas I have.
As one of my objectives is to learn Babylon only using JS Vanilla and not typescript, I tried to find a simple tutorial that used JS only.
I found this somewhat old tutorial about a bowling game and tried to give it a go.
However, when I tried to implement it I noticed some odd behaviors and couldn’t find out why.
Here is a Playground link replicating the problems I’m having:
It has a ball, a lane and some pins.
If you click with the mouse in the lane, it will apply an impulse to the ball.
The longer you hold the mouse click, stronger will be the impulse.
The ‘R’ key reset the pins.
I have 2 questions that was hoping you could help me with.
The first and my main issue is related to the Physics of the pin…
When you start the scene they simple ‘explode’ and start behaving odd.
If I check the debugger, I can see that their quaternation keeps being updated, but I don’t know why.
I can’t find anything in this code that could be the responsible for that.
My second question is related to the follow camera, I’m having problems to understand why a specific object is not being updated.
When you throw the ball using the mouse click, a follow camera is created on the left bottom that follows the ball.
Originally on the code it had a followObject that was used instead of the ball to avoid having the camera spinning together with the ball.
You can find it on the line 274 of the playground code commented.
On the line 275 when we have ‘followObject.position = ball.position;’, due to JS using assigments by reference, I was expecting the followObject to use the same position JS object of the ball, and thus be updated everytime the ball position changed.
But this didn’t happen, the followObject was kept at the original position and the camera didn’t follow it even when the ball was moving.
I left the original code commented so you can see how the follow camera should behave, however, it is spinning together with the ball as Im using the ball as the target.
Really appreciate if you can give some guidance on those basic concepts.
And I’m keen to keep learning more about babylon,
Regards,
RR
EDIT: Simpler playground for each problem:
1 - https://playground.babylonjs.com/#4WANIF#1
Pins doesn’t “explode” but they start moving radomly
2 - https://playground.babylonjs.com/#GKAJJE#1
Follow mesh not changing position according to the ball