Question about CharController and NAN error

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Question about CharController and NAN error

Post by Danthekilla »

Hey everyone :) I hope all is well!

What are the pros and cons between the "SimpleCharacterController" and the "SphereCharacterController" ?

I see they are both less featured and complex than the full CharacterController but what the performance and quality differences between the two?

Also as a seperate issue I am getting a NAN when changeing a dynamic sphere to kinimatic on the collision with a static object.
Code below

This is the code I use to throw the physicsball:

Code: Select all

            MyPhysics = new Sphere(in_Position, 0.3f, 10);
            MyPhysics.LinearVelocity = in_Direction * 30;
            MyPhysics.CollisionInformation.Events.ContactCreated += HasHitEvent;
            PhysicsManager.GET.PhysicsSpace.Add(MyPhysics);
This is what I use to stop it when it collides with a static terrain object (also I would love to know if there is a better way.)

Code: Select all

        private void HasHitEvent(EntityCollidable in_Sender, Collidable in_Other, CollidablePairHandler in_Pair, ContactData in_Contact)
        {
            EntityCollidable HitObj = in_Other as EntityCollidable;
            if (HitObj != null)
            {
                if(HitObj.Entity.IsDynamic)
                {
                    LivingPhysicsEntity HitEntity = HitObj.Entity.Tag as LivingPhysicsEntity;
                    if(HitEntity != null)
                    {
                        HitEntity.DoDamage();
                    }
                }
                else
                {
                    //We are currently assumeing that this is a hit against the terrain
                    if (MyPhysics.IsDynamic)
                    {
                        MyPhysics.AngularMomentum = Vector3.Zero;
                        MyPhysics.LinearMomentum = Vector3.Zero;
                        MyPhysics.BecomeKinematic();
                    }
                }
            }
        }
When I call MyPhysics.BecomeKinematic(); on the sphere after 2 frames its position is NAN

Anyone have any ideas...?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Question about CharController and NAN error

Post by Norbo »

What are the pros and cons between the "SimpleCharacterController" and the "SphereCharacterController" ?

I see they are both less featured and complex than the full CharacterController but what the performance and quality differences between the two?
The SphereCharacterController is spherical and more robust in almost every way. It can't step up or down discontinuously, though- it just slides up and down things if the slope is gentle enough. However, if discontinuous stepping is required, the CharacterController is vastly better than the SimpleCharacterController in terms of robustness.

The SphereCharacterController is usually a bit faster than the SimpleCharacterController, especially with multithreading. If you'd like to investigate their performance differences more, check out the CharacterStressTestDemo in the BEPUphysicsDemos (development version). Right now it's over a thousand CharacterControllers and SphereCharacterControllers (and a couple hundred boxes) on a mesh and runs quite nicely on my old Q6600.

The SimpleCharacterController's main/only advantage is that it's one class instead of five. :)
also I would love to know if there is a better way.
A minor detail, but by storing the tag in the entity collidable's tag instead of the entity's tag, some of that logic could be short circuited.
When I call MyPhysics.BecomeKinematic(); on the sphere after 2 frames its position is NAN
This appears to be caused by constraints persisting through the kinematic change. If both entities in a constraint turn out to be static at the time of solving due to the switch, it will still attempt to solve the pair due to now-outdated cached data, but fail because they're both kinematic.

I'll try to get a fix into the development version soon.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Question about CharController and NAN error

Post by Norbo »

That was about an order of magnitude more complicated than I had predicted, but it should be fixed now: http://bepuphysics.codeplex.com/SourceC ... evelopment
Post Reply