RigidBody has FreezePosition in Constraints, but Physics For ECS does not.
Is this the best way to do it?
public class ConstraintsPositionAuthoring : MonoBehaviour
{
public bool3 linerConstrainedAxes; // x, y, z
public class Baker : Baker<ConstraintsPositionAuthoring>
{
public override void Bake(ConstraintsPositionAuthoring authoring)
{
// The entity will be moved
var entity = GetEntity(TransformUsageFlags.Dynamic);
// create PhysicsJoint
Constraint constraint = new()
{
ConstrainedAxes = authoring.linerConstrainedAxes,
Type = ConstraintType.Linear,
Min = 0,
Max = 0,
SpringFrequency = Constraint.DefaultSpringFrequency,
SpringDamping = Constraint.DefaultSpringDamping
};
FixedList512Bytes<Constraint> fixedList = new(){
constraint
};
PhysicsJoint physicsJoint = new();
physicsJoint.SetConstraints(fixedList);
// create PhysicsConstrainedBodyPair
PhysicsConstrainedBodyPair bodyPair = new(entity, Entity.Null, false);
// add them
AddComponent(entity, physicsJoint);
AddComponent(entity, bodyPair);
}
}
}
memo: As for Rotation, it is possible by setting Infinity to Inertia Tensor in the Override Default Mass Distribution in the Advanced section of Physics BodyAuthoring.