I am trying to create an entity at runtime that behaves like a Rigidbody. I don’t want to use bakers for this.
Right now I am trying the following (as inspired by various posts and the docs), but this instantly results in the entity’s position and rotation becoming all NaNs.
entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity = entityManager.CreateEntity();
entityManager.SetName(Entity, "__dynamic");
entityManager.AddComponentData(Entity, new LocalTransform {
Position = transform.position
});
entityManager.AddComponentData(Entity, new PhysicsDamping { Linear = 0.01f, Angular = 0.05f });
entityManager.AddComponentData(Entity, new PhysicsGravityFactor { Value = 1f });
entityManager.AddComponentData(Entity, new PhysicsMass { InverseMass = 1f, InverseInertia = new float3(1f,1f,1f) });
entityManager.AddComponentData(Entity, new PhysicsMassOverride { IsKinematic = 0 });
entityManager.AddComponentData(Entity, new PhysicsVelocity { });
entityManager.AddComponentData(Entity, new Simulate { });
entityManager.AddSharedComponentManaged(Entity, new PhysicsWorldIndex { Value = 0 });
Appreciate the reply, but this did not solve my issue. Even with PhysicsMassOverride.IsKinematic set to 1, any physics update immediately gives me NaNs, even if I reset the local transform manually
UPDATE: You were close, turns out I needed to also set the PhysicsMass.Transform. Thanks for the advice!