Recently I’ve remembered about how I should make this post, so I am.
There is a “hidden” camera property that allows the free camera with collision to fall without moving at all. Normally when you walk off the platform in the babylon.js collisions playground demo, after falling for a little you can look up and see the cube you were just by, not getting any smaller since you are not falling. press and arrow key again and it will get smaller, until you let go and inertia runs out, returning you to the floating state.
Add the line camera._needMoveForGravity = true;, run the code, and walk off the platform again, and when looking at the box it will get smaller and smaller because you will never stop falling.
The property contradicts itself by stating that you have to move to have gravity, when in fact it has a reversed effect. by default it is set to false.
It is not in the API documentation, and I feel it is not very known about.
There are many hidden properties in Babylon.js, these are private properties and are there to support the internal code. All private properties start with an underscore and are not documented in the API since they are not public properties. As such there is no guarantee that they will remain the same overtime though the public properties they support will. Since BJS is open source they can be found and set directly. In particular use cases they may produce an effect you need but might not be available in a later version and can produce unwanted effects in other circumstances.
If you think it necessary you can always make a request for a change to make a private property public though potential adverse consequences need to be considered.
Wait, if anything starting with _ isn’t documented, why is this one? It’s in the camera’s API documentation.
EDIT: Why can’t I choose to posts as solutions? Both of you have really good explanations and I can’t choose both! @JohnK your post is also a solution.
Sorry Givo… I didn’t mean to show you an illegal command. It’s the only way I know… to make a gravity-active cam… start falling automatically. Perhaps @deltakosh will tell us the more-correct way to do that (kindly).
Because of a typo. API is generated directly from the code. Currently code is
/** hidden */
public _computedViewMatrix = Matrix.Identity();
should be
/** @hidden */
public _computedViewMatrix = Matrix.Identity();
PR submitted
This particular property is made public so that it is available in other classes internally but should not be accessed externally. However it is neither illegal nor a bug to use it provided you are aware of the consequences of doing so and are happy that for your use it is safe to do so. If it works for you its fine to use it.
Suppose both class A and class B require _hiddenProperty = false and class C requires _hiddenProperty = true. You write code that sets _hiddenProperty to true, later in your project you add something that needs class C, so far so good. Then you add in something that needs class A or class B, since _hiddenProperty is now true your code will have a bug that could be very hard to trace.