satguru

BabylonJS CharacterController

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

Share this post


Link to post
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.

Share this post


Link to post
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.

 

Share this post


Link to post
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

 

Share this post


Link to post
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.  

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.