Jump to content

BabylonJS CharacterController


satguru
 Share

Recommended Posts

@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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

@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.

 

Link to comment
Share on other sites

@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

 

Link to comment
Share on other sites

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.  

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

  • 1 month later...

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);
}
Link to comment
Share on other sites

  • 6 months later...

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

@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?


 

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...