currently im trying to build up a character controller that interacts with an physics engine in a way that the character both can be controlled by player input as well as can be hit by flying imposters / collide with dynamic boxes.
As far as i know the basic idea is to get the current velocity each frame, manipulate it and set it again (tweaking the pyhsics of the character a little).
Did anyone tried this before or found an example? I could only find examples of controllers that did not interact with an pyhsics engine.
I will maybe provide a sandbox if this problem persists longer for me. (currently im a bit short on time ) Also i could not find much information at all on how to combine a controller with a physics engine.
Best reference i have so far is the sketchbook project of Jan Blaha (github-repo), whose character controller works a lot like i would expect things to work. Hes uses cannon btw.
I was wondering if i could reproduce a similar controller only using the babylonjs wrappers.
The interesting part is in the Character class form line 827, where he alters the resulting velocity for the character.
@MackeyK24 i guess you have been talking about this unity function in the other thread?
But isnt this anything more than a “moveWithCollisions” as in babylonjs? Or is the simulated velocity (coming from the physics engine) injected behind the scenes?
I will have a closer look into the CharacterController of sketchbook, and report when i manage to build a similar controller.
It should be possible, though you’d have to modify the code by removing the sleep() calls when there are no key presses and somehow not erasing the velocity other objects cause to your character in setLinearVelocity()
@to5ta, this is awesome, and thank you for sharing!
I think the benefit of moveWithCollisions is very smooth movement, even up and down slopes. It would be awesome if you figured out how to calculate the normals to change velocity on slopes
Recreating this smooth movement with a physics engine is challenging. In the Playground (https://www.babylonjs-playground.com/#3EDS3A#96) within the Question post linked above, there is a small issue I haven’t solved: There is a small initial “bump” in movement when going down a slope
If you do decide to go with a physics engine, you could leverage Friction, which should give you slope angle-dependent velocity
Yes, exactly Global surface slopes are calculated now, moving vector transformation still tbd.
This is what i have so far…
At least the platform interaction problem can be observed already… guess collision objects’ classes have to be detected and movement has to be treated accordingly (aka hit platform? move with platform)