This is again for NYNS. For Bhop, when you press a and look left you gain some speed, look left, AND you current direction of movement (say a vector3 of (0, 0, 1)) rotates with you. So if you look 90 degrees to you left, you move about as fast as when you were moving before.
Basically, you linear velocity also rotates.
Is this possible to do? Or do I have to make a weird set of functions?
I did basically the same thing. Simply changing linear velocity with the camera direction multiplied by the current velocity length should do the trick. https://playground.babylonjs.com/#LPX1FM#16
Then to modulate your velocity, you can change the linearDamping or clamp the linear velocity to a maximum before using it with the camera direction multiplication.
I added the code so that you can only airstrafe, well, in the air. But the jump heights I feel are inconsistent (like starts low but when you start moving you jump higher) and that you gain speed too quickly. I’ve tried dividing things here and there by 2 to make you gain speed slower, but it either makes your speed NaN or stops you completely.
I couldn’t reproduce your behavior: I didn’t get a NaN.
1 very important thing with physics is the time. In order to have consistent behavior, do not make your computation based on frame count (like the jt variable) but base everything on time. Frame rate may be inconsistent. I get between 42 and 55 fps. So jt should be a delay in seconds (or any other time unit) and not frame index.
If you change line 328 or 322 to player.physicsImpostor.setLinearVelocity(velocity/2); and then airstrafe in the direction you change the line, you will go ZOOM and get NaN.
I should also make jt clear. It stands for jump time, and is set to 10 when you jump. I think you saw the code that makes it go down every frame. I use it so that when you jump you won’t fling into the air. The mesh that detects if you are on the ground is a bit longer than it needs to be, and if you remove the code for jt so you can jump if you are just touching the ground, every frame the mesh (called playerj) is in the ground it translates you up more. They basically stack over 10 frames to launch you into the air.
I will add code for the delta time, though. I’ve worked with it before and shouldn’t be too hard.
EDIT:
I added the delta time updater and incorporated it with the jumping. Jump height is now SUPER consistent.