Page 1 of 1

Good teleporting method - CharacterController example

Posted: Fri Jun 29, 2012 1:56 pm
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?

Re: Good teleporting method - CharacterController example

Posted: Fri Jun 29, 2012 3:10 pm
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.

Re: Good teleporting method - CharacterController example

Posted: Fri Jun 29, 2012 4:28 pm
by Spankenstein
Ok, I'll remove the extra code. Thanks.