- Home /
Adding constraints to PhysicsBody of the Unity.Physics DOTS package
I am testing the Unity DOTS Physics package and I am currently trying to create character that is affected by physics.
I have created a capsule to represent the character, the character has a PhysicsShape of type capsule. Now I am trying to add constraints to the rotation of x and z to prevent the character from falling over as soon as it starts moving. I can't seem to find any properties on either the PhysicsShape, PhysicsBody, PhysicsMass, PhysicsDamping or PhysicsVelocity components to add those constraints, it also doesn't seem to be documented anywhere.
These are the used components and how everything is converted to an entity.
Is this not yet supported by the physics package?
And if it is supported, how could I add those constraints?
Answer by NT_Ninetails · Dec 22, 2020 at 12:14 PM
@ Ruinerwarrior Unity.Physics 0.5.1-preview.2
You will will either have to modify the joint in code after the GameObject is converted into an entity, or create the PhysicsJoint in code and modify the constraints before creating the Entity.
// Get the PhysicsJoint entity and modify constraints
PhysicsJoint joint = EntityManager.GetComponentData<PhysicsJoint>(JointEntity);
FixedList128<Constraint> constraintList = joint.GetConstraints();
Constraint constraint = constraintList[0];
constraint.Type = ConstraintType.Angular;
constraint.SpringDamping /= 100;
constraint.SpringFrequency /= 100;
constraint.Min = 0;
constraint.Max = 90;
constraintList[0] = constraint;
joint.SetConstraints(constraintList);
EntityManager.SetComponentData(JointEntity,joint);
// Note this is just an example for a proof of conceopt, you should do this in a IJobChunk using a CommandEntityBuffer.ParallelWriter with burst
Your answer
![](https://koobas.hobune.stream/wayback/20220613003539im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to capsule cast from within Entities.ForEach job? ECS 1 Answer
Can not add PhysicsCollider at runtime Unity in ECS 1 Answer
2D 360 degress platformer example needed 0 Answers
(DOTS) How to slowly rotate an object to face a point? 1 Answer
Cannot move anything with pure ECS Physics instantiation 1 Answer