Good teleporting method - CharacterController example

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Good teleporting method - CharacterController example

Post by Spankenstein »

I'm looking to safely teleport a dynamic object from one position to another.

This is what I am using based on the CharacterController method:

Code: Select all

            Vector3 position = Parent.Position;
            position.X = value;

            Parent.Entity.Position = position;
            var orientation = Parent.Entity.Orientation;
            
            // The re-do of contacts won't do anything unless we update the collidable's world transform
            Parent.Entity.CollisionInformation.UpdateWorldTransform(ref position, ref orientation);

            // Refresh all the narrow phase collisions
            int numPairs = Parent.Entity.CollisionInformation.Pairs.Count;

            for (int i = 0; i < numPairs; ++i)
            {
                // Clear out the old contacts  
                // This prevents contacts in persistent manifolds from surviving the step
                // Old contacts might still have old normals which block motion
                Parent.Entity.CollisionInformation.Pairs[i].ClearContacts();
                Parent.Entity.CollisionInformation.Pairs[i].UpdateCollision((float)gameTime.ElapsedGameTime.TotalSeconds);
            }
Are all the steps necessary for all dynamic objects and have I missed anything that might be considered important?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Good teleporting method - CharacterController example

Post by Norbo »

The CharacterController has to do that sort of stuff due to its strong requirements and its position in the space update. It is very likely that emulating the character controller's discontinuous stepping for arbitrary teleportation will be completely unhelpful for non-characters. Note that these precautions on the character would not stop an object from being teleported through a wall or something- the character has other special protections to stop stepping from doing that.

Just directly setting the entity Position and Orientation or equivalent properties is sufficient/'safe' for dynamic entities in normal circumstances.
Spankenstein
Posts: 249
Joined: Wed Nov 17, 2010 1:49 pm

Re: Good teleporting method - CharacterController example

Post by Spankenstein »

Ok, I'll remove the extra code. Thanks.
Post Reply