Change position of Entity

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
oclock
Posts: 2
Joined: Thu Jul 25, 2019 6:31 pm

Change position of Entity

Post by oclock »

Note: I'm using V1 as I'm looking for a deterministic physics solution.

I need to be able to move an entity by setting it's position (in one case a character controller) from A->B at any time before or after my space.Update(). This could be through walls so applying a velocity isn't ideal.

I notice that sometimes it will move, however it's not consistent. Would setting the entire Matrix3x3 work? Maybe making it so it's not dynamic, setting position, back to dynamic?

What is the best way to update my entities position so it will be exactly what I expect?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Change position of Entity

Post by Norbo »

Setting the Entity.Position property will do this. It directly teleports the body to the new location with no conditions. If it appears to fail sometimes, there's probably something else going on outside of the position setter.

Notably, v2 has a locally deterministic mode just like v1, and it's massively faster. Unless you are looking for cross platform determinism (and so are using one of the fixed point versions of v1), v2 would work.
SugarGlider
Posts: 11
Joined: Mon Aug 05, 2019 12:06 pm

Re: Change position of Entity

Post by SugarGlider »

Hi

I'm trying to to this using v2 and i'm wondering how to do it. There is obviously no Entity.Position in v2. My code is below and it runs, the model position does get updated, but a couple of seconds after the updated item collides it crashes. I'm supprised as i see the objects collide and slide for a second or two before the crash.

Code: Select all

GetPhysicsPoseData(wrlModel.PropBasic, out PVector3 position, out PQuaternion rotation);

            // Directly Set Position and Rotation For Existing Physics Body
            if (wrlModel.PhysicsDynamic)
            {
                PhysicsSim.Bodies.GetDescription(wrlModel.PhysicsHandle, out BodyDescription desc);

                desc.Pose.Position      = position;
                desc.Pose.Orientation   = rotation;

                PhysicsSim.Bodies.ApplyDescription(wrlModel.PhysicsHandle, desc);
            }
            else
            {
                PhysicsSim.Statics.GetDescription(wrlModel.PhysicsHandle, out StaticDescription desc);

                desc.Pose.Position      = position;
                desc.Pose.Orientation   = rotation;

                PhysicsSim.Statics.ApplyDescription(wrlModel.PhysicsHandle, desc);
            }
The stack trace for the crash is..

Code: Select all

Message:		Object reference not set to an instance of an object.

Stack Trace:		
   at BepuPhysics.CollisionDetection.NarrowPhase`1.UpdateConstraint[TBodyHandles,TDescription,TContactImpulses,TCollisionCache,TConstraintCache](Int32 workerIndex, CollidablePair& pair, Int32 manifoldTypeAsConstraintType, TConstraintCache& newConstraintCache, TCollisionCache& collisionCache, TDescription& description, TBodyHandles bodyHandles) 
	in C:\BepuPhysics\CollisionDetection\NarrowPhaseConstraintUpdate.cs:line 175
   at BepuPhysics.CollisionDetection.ConvexOneBodyAccessor`4.UpdateConstraintForManifold[TContactManifold,TCollisionCache,TCallBodyHandles,TCallbacks](NarrowPhase`1 narrowPhase, Int32 manifoldTypeAsConstraintType, Int32 workerIndex, CollidablePair& pair, TContactManifold& manifoldPointer, TCollisionCache& collisionCache, PairMaterialProperties& material, TCallBodyHandles bodyHandles)
	in C:\BepuPhysics\CollisionDetection\ContactConstraintAccessor.cs:line 230
   at BepuPhysics.CollisionDetection.NarrowPhase`1.UpdateConstraintForManifold[TContactManifold,TCollisionCache,TBodyHandles](Int32 workerIndex, CollidablePair& pair, TContactManifold& manifold, TCollisionCache& collisionCache, PairMaterialProperties& material, TBodyHandles bodyHandles)
	in C:\BepuPhysics\CollisionDetection\NarrowPhaseConstraintUpdate.cs:line 308
   at BepuPhysics.CollisionDetection.NarrowPhase`1.UpdateConstraintsForPair[TContactManifold,TCollisionCache](Int32 workerIndex, CollidablePair& pair, Void* manifoldPointer, TCollisionCache& collisionCache)
	in C:\BepuPhysics\CollisionDetection\NarrowPhaseConstraintUpdate.cs:line 348
   at BepuPhysics.CollisionDetection.CollisionBatcher`1.ProcessConvexResult(ConvexContactManifold* manifold, PairContinuation& continuation)
	in C:\BepuPhysics\CollisionDetection\CollisionBatcher.cs:line 322
   at BepuPhysics.CollisionDetection.CollisionTasks.ConvexCollisionTask`8.ExecuteBatch[TCallbacks](UntypedList& batch, CollisionBatcher`1& batcher)
	in C:\BepuPhysics\CollisionDetection\CollisionTasks\ConvexCollisionTask.cs:line 137
   at BepuPhysics.CollisionDetection.CollisionBatcher`1.Flush()
	in C:\BepuPhysics\CollisionDetection\CollisionBatcher.cs:line 299
   at BepuPhysics.CollisionDetection.CollidableOverlapFinder`1.DispatchOverlaps(Single dt, IThreadDispatcher threadDispatcher)
	in C:\BepuPhysics\CollisionDetection\CollidableOverlapFinder.cs:line 141
   at BepuPhysics.Simulation.CollisionDetection(Single dt, IThreadDispatcher threadDispatcher)
	in C:\BepuPhysics\Simulation.cs:line 275
   at BepuPhysics.PositionFirstTimestepper.Timestep(Simulation simulation, Single dt, IThreadDispatcher threadDispatcher)
	in C:\BepuPhysics\PositionFirstTimestepper.cs:line 62
   at BepuPhysics.Simulation.Timestep(Single dt, IThreadDispatcher threadDispatcher)
	in C:\BepuPhysics\Simulation.cs:line 342
Thanks
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Change position of Entity

Post by Norbo »

Simulation.Bodies.GetBodyReference(handle) is an easier way to handle bodies. The BodyReference has a Pose property, among lots of other stuff.

Statics don't have an equivalent StaticReference (though I might add one), but their lookup is very simple. Simulation.Statics.Poses[Simulation.Statics.HandleToIndex[handle]] would work. You could do something similar for bodies, it just requires an extra layer of indirection to deal with the body sets.

As for the crash, it's hard to guess what would cause that. I'd need a minimal repro (like a modified demo) showing the crash to figure it out.
SugarGlider
Posts: 11
Joined: Mon Aug 05, 2019 12:06 pm

Re: Change position of Entity

Post by SugarGlider »

The crash happens when i move a static mesh only dynamic are fine. It strikes a second or two after the next body collides with it. Thats when i return the static description update its pose and apply it again. If i change the static models pose using the method u gave for updating statics, the crash does not happen. I will try and get a demo to reproduce incase its a sign of some deeper problem.

Thanks
Post Reply