Recently, I did another playground that used simple ray-casting… so now I’m an expert. (not)
Splash, take a look at https://www.babylonjs-playground.com/#WECN4N#3 - lines 118-130 area. (I changed all ‘this’ to be ‘camera’… maybe wiser in this situation).
I also changed jump height from 6, to 16… just to help me test stuff.
Um, I don’t use a target… to derive a direction for the raycast. I just force the direction to be BABYLON.Vector3.Down(). I KNOW your player/cam is around 4.02 above the ground (and same distance above anything the camera/player jumps-onto).
The ‘hit’ object that is returned by the raycast… contains a .distance which we can use. You can watch line 128 @ console… and see that cam never gets higher than 20, so I made my raycast length be 30… long enough to HIT floor even when cam/player is at top of jump-height.
The raycast is not a performance issue, because we just do ONE cast at the beginning of a jump attempt.
Wha-da-ya-think? No more lines 106-109 hassles, eh? (flags-o-many) Abdullah had a pretty good idea, and we just needed to wire it into your system… and see if it works. Once we removed the need for a target, and instead, aimed the raycast straight down below the camera… it became more useful to us.
There MAY BE problems ahead yet (for your app), but maybe not. Perhaps this camera “butt-cast” will work good for ya.
I see, in BUGS… that you are beginning the problems of WHO IS BOSS… physicsImpostor… or animation keys. Maybe keyframe-animating physics objects worked in 3.0, but that is not good. technically, it should never work… as the impostor is the boss of the mesh… and impostors ONLY move when given a physics-approved force. Keyframes… setting non-physics properties… are not a physics-approved force. Here’s your “k-jumper” playground… but using a physics-approved force in line 57.
Perhaps a smarter way… end the keyframe mesh-animation… with mesh positioned a tiny distance above floor… and right there… either by animation onEnd callback or by an animation event… add the impostor RIGHT THEN. Always remove the impostor before the keyframe animation starts… and always add it again, just after anim ends. That’s more proper, I think.
Possibly soon… you will be talking about camera/player being TOTALLY controlled-by physics forces. I think @givo and someone else… went down that trail… within the last year… and they both went insane. hah. (mostly from trying to keep camera from sliding (downhill) when player stops on inclines)
I hope I have been helpful. Party on!