satguru Posted December 10, 2017 Share Posted December 10, 2017 A 3rd person character controller for BabylonJS source : https://github.com/ssatguru/BabylonJS-CharacterController docs: https://ssatguru.github.io/BabylonJS-CharacterController/ demo : https://ssatguru.github.io/BabylonJS-CharacterController/demo/ git download: https://github.com/ssatguru/BabylonJS-CharacterController/releases npm: https://www.npmjs.com/package/babylonjs-charactercontroller Originally developed as part of my Vishva project Dr. Aaron Dishno, Spankied, jodo and 9 others 10 2 Quote Link to comment Share on other sites More sharing options...
hunts Posted December 10, 2017 Share Posted December 10, 2017 this will be good for my rpg game satguru 1 Quote Link to comment Share on other sites More sharing options...
RNull Posted December 11, 2017 Share Posted December 11, 2017 @Deltakosh This would be a great addition for Babylon.js . I think it is quite well done not underestimating the fact that writing a good character controller is never easy. @satguru Great job! satguru 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 11, 2017 Share Posted December 11, 2017 Missing something to add of new animations rather than default animations. Something like addAnim() would be better, I think. Otherwise it's interesting, good work. satguru 1 Quote Link to comment Share on other sites More sharing options...
satguru Posted December 11, 2017 Author Share Posted December 11, 2017 @RelativeNull, Thanks @Dad72, I do not understand the need for addAnim(). The user can add any animation to the avatar/player skeleton. The CharacterController will only use the one it needs and ignore the rest.. As far as default animations are concerned the user can call them whatever they want. If the name is different from the default animation name they can use the setWalkAnim(), setRunAnim() and so on to map them to the default animation. Example to map "myWalk" animation to Walk animation -> setWalkAnim("myWalk",1,true); Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 12, 2017 Share Posted December 12, 2017 In case we want a swimming animation, or punch, I do not see myself using setWalkAnim () or setRunAnim () which is not coherent. I think addAdnim () allows you to add a custom animation list and use them directly. This allows you to add 20 animations in a array and give them a name. Otherwise add a setAnim () without using Walk, Run ... in setWalkAnim. because if I add a punch animation, setWalkAnim is not adequate and there is no setPunchAnim. setAnim() will be more direct ou addAnim(). I may not have understood the class yet. Quote Link to comment Share on other sites More sharing options...
satguru Posted December 13, 2017 Author Share Posted December 13, 2017 @Dad72 I think I see your concern. Maybe instead of setWalkAnim() or setWalkBackAnim() I should call it setForwardAnim() , setBackAnim() and so on. This way they would make sense for walk, fly, swim etc. setAnims() and passing an anim array makes sense too. With this the name doesn't matter. 1st is for going forward, 2nd for going back and so on. I will add that . I like separate methods because in an IDE auto complete and type assist guides you and helps you discover various functionalities. I am also thinking of adding a pauseAnim() and a resumeAnim(). This will allow user to play any animation while the CharacterController continues controlling the movement. Dad72 1 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted December 13, 2017 Share Posted December 13, 2017 Thanks for the additions. Quote Link to comment Share on other sites More sharing options...
RNull Posted December 15, 2017 Share Posted December 15, 2017 @satguru One question. Did you write this based on a physic engine? How easy would it be to integrate it to Cannon.js or Oimo.js ? Quote Link to comment Share on other sites More sharing options...
satguru Posted December 15, 2017 Author Share Posted December 15, 2017 @RelativeNull This is not based on physics engine. I have updated the document to reflect this. Here is what it says now. It uses the collider and moveWithCollision() function to move the character around. It uses some of the physics kinematic equations to calculate movements like jump, fall, slide. It does not use any physics engine. It does not react to or apply forces. The unityt3d document nicely explains why physics engine may not be ideal for this https://docs.unity3d.com/Manual/class-CharacterController.html Quote Link to comment Share on other sites More sharing options...
RNull Posted December 16, 2017 Share Posted December 16, 2017 19 hours ago, satguru said: @RelativeNull This is not based on physics engine. I have updated the document to reflect this. Here is what it says now. It uses the collider and moveWithCollision() function to move the character around. It uses some of the physics kinematic equations to calculate movements like jump, fall, slide. It does not use any physics engine. It does not react to or apply forces. The unityt3d document nicely explains why physics engine may not be ideal for this https://docs.unity3d.com/Manual/class-CharacterController.html I agree there is a debate whether the character controllers should be rigid body or kinematic body. What you have done here is the kinematic body approach and sincerely I do think that kinematic is better than rigid for the purpuse . However, if someone integrates a physics engine like Oimo or Cannon into BJS ( and BJS makes it easy as hell to do so ), would your controller work and interact with other physic bodies ? I would probably look at this as a next evolution step for your controller. I am thinking of this as something which hopefully later can be shipped with BJS. To be able to do so, you need to make it compatible to the physic engines available. Quote Link to comment Share on other sites More sharing options...
satguru Posted December 17, 2017 Author Share Posted December 17, 2017 @RelativeNull Currently the controller would not interact with other physic bodies. If instead of moveWithCollision(), had I used move with force or impulse then that would have worked. With the current approach one would have to capture a collision event and apply some force. I will continue looking into it. Quote Link to comment Share on other sites More sharing options...
Spankied Posted December 21, 2017 Share Posted December 21, 2017 brilliant satguru 1 Quote Link to comment Share on other sites More sharing options...
Spankied Posted February 4, 2018 Share Posted February 4, 2018 How does the controller know which animation ranges on your avatar correspond to walk/run/slide etc? In other words, how do you retarget animations to a new skeleton? Edit: figured it out from demo/index.html function setAnimationRanges(skel){ delAnimRanges(skel); skel.createAnimationRange("fall",0,16); skel.createAnimationRange("idle",21,65); skel.createAnimationRange("jump",70,94); skel.createAnimationRange("run",100,121); skel.createAnimationRange("slideBack",125,129); skel.createAnimationRange("strafeLeft",135,179); skel.createAnimationRange("strafeRight",185,229); skel.createAnimationRange("turnLeft",240,262); skel.createAnimationRange("turnRight",270,292); skel.createAnimationRange("walk",300,335); skel.createAnimationRange("walkBack",340,366); } EarthLaunch 1 Quote Link to comment Share on other sites More sharing options...
Boz Posted August 13, 2018 Share Posted August 13, 2018 Hello @satguru, thanks for this great addition ! It really fits my needs, except one thing : I prefer to use the mouse to move left and right instead of A and D keys. But you disable the mouse from moving when the character is walking. Is there any solution to enable the mouse controls and character movement in the same time ? Thank you very much Quote Link to comment Share on other sites More sharing options...
satguru Posted August 13, 2018 Author Share Posted August 13, 2018 Hi @Boz 4 hours ago, Boz said: It really fits my needs, except one thing : I prefer to use the mouse to move left and right instead of A and D keys. But you disable the mouse from moving when the character is walking. when you say "move left and right" do you mean strafe left or right or turn left or right? Currently you can turn left and right using the mouse but you have to press left mouse button and move the mouse to do that. Are you looking for free mouse look? In other words turn the character by just moving the mouse instead of pressing and moving the mouse? Quote Link to comment Share on other sites More sharing options...
Boz Posted August 13, 2018 Share Posted August 13, 2018 Hey, The fact is I can't use the mouse during the character is moving.. I know about the pointerLock but it doesn't solve the problem. I looked into your code but don't understand if you prevent mouse action during key_pressed or something.. Could you help ? Quote Link to comment Share on other sites More sharing options...
satguru Posted August 14, 2018 Author Share Posted August 14, 2018 @Boz Sorry, I am not sure I understand. I am not preventing any mouse movement or action. When you press mouse left button and move the mouse it rotates the arcrotate camera around the character and if the character is moving it rotates the character too. Are you saying that you do not want the camera to rotate when the mouse is moved? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.