So, after attempting to add physics components to entities that are being created in-script, i am unable to get an entity with a functional collisions(they do not interact with anything) or physics (applying values to the
PhysicsVelocity component influences nothing)
what am i doing wrong?
Code
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity NewEntity = entityManager.CreateEntity(
typeof(Translation),
typeof(Unity.Physics.PhysicsCollider),
typeof(Scale),
typeof(Unity.Physics.PhysicsVelocity),
typeof(Unity.Physics.PhysicsMass),
typeof(Unity.Physics.PhysicsDamping)
);
entityManager.SetComponentData ( NewEntity, new Scale {
Value = 0.3f
});
var desc = new RenderMeshDescription(
mesh,
material
);
RenderMeshUtility.AddComponents(
NewEntity,
entityManager,
desc
);
entityManager.SetComponentData ( NewEntity, new Translation { Value = Position });
entityManager.SetComponentData ( NewEntity, new Unity.Physics.PhysicsMass {
Transform = new Unity.Mathematics.RigidTransform(Quaternion.identity, new Unity.Mathematics.float3(Position[0],Position[1],Position[2])),
InverseMass = 1,
AngularExpansionFactor = 6,
InverseInertia = new Vector3(0.1f, 0.1f, 0.1f)
});
entityManager.AddSharedComponentData(NewEntity, new Unity.Physics.PhysicsWorldIndex {Value = 0});
var collider = Unity.Physics.BoxCollider.Create(
new Unity.Physics.BoxGeometry {BevelRadius = 0.1f, Center = Position, Orientation = Quaternion.identity, Size = new Unity.Mathematics.float3(1,1,1)}
);
entityManager.SetComponentData(NewEntity, new Unity.Physics.PhysicsCollider {Value = collider});
using
Unityphysics 0.51-preview.32
Entities 0.51.0-preview.32