In traditional physics engine,we can scale the mesh collider by changing the scale in Transform property. What about in dots physics,I’ve tried adding the scale property but it doesn’t work.
As of Unity Physics 1.3 you can scale any collider at runtime with Collider.BakeTransform.
You can cast collider.ColliderPtr
to a specific collider pointer type to change it’s data directly this way.
Note: unsafe code needs to be enabled in Player Settings for this to compile.
using Unity.Entities;
using Unity.Mathematics;
using Unity.Physics;
public partial class ScaleAllSpheresSystem : SystemBase
{
protected override void OnUpdate()
{
float r = 1f + math.sin((float)SystemAPI.Time.ElapsedTime);
new ScaleJob { r = r }.ScheduleParallel();
}
[Unity.Burst.BurstCompile]
//[WithAll( typeof(YOUR_TAG_COMPONENT_SO_NOT_ALL_SPHERES_ARE_INCLUDED) )]
//[WithNone( typeof() )]
partial struct ScaleJob : IJobEntity
{
public float r;
public unsafe void Execute(ref PhysicsCollider collider)
{
if (collider.Value.Value.Type == ColliderType.Sphere)
{
var sphereColliderPtr = (SphereCollider*) collider.ColliderPtr;
var geo = sphereColliderPtr->Geometry;
geo.Radius = r;
sphereColliderPtr->Geometry = geo;
}
}
}
}
Thanks!But exactly I want to scale the MESH COLLIDER whitch doesn’t have the “Geometry property”.