Skip to content

Adding an interpolation for physics body #3

@grapefruitlips

Description

@grapefruitlips

Hello,

How can I add an interpolation for physics body?

PhysicsGraphicalSmoothing smoothing = new PhysicsGraphicalSmoothing()
{
    ApplySmoothing = 1,
};
new PhysicsGraphicalInterpolationBuffer
{
    PreviousTransform = Unity.Physics.Math.DecomposeRigidBodyTransform((float4x4)pb.transform.localToWorldMatrix),
    PreviousVelocity = new PhysicsVelocity(){ Linear = float3.zero, Angular = float3.zero}
};

Hot to add it to the rigidbody's entity? or to PhysicsWorld?

For example, for MotionVelocity I see we can add it like this:

var motionVelocities = PhysicsWorld.MotionVelocities;
motionVelocities[dynamicIndex] = new MotionVelocity()...

and then finding it like

int rbIndex = PhysicsWorld.GetRigidBodyIndex(new Entity() { Index = pb.Entity });
var rb = PhysicsWorld.Bodies[rbIndex];

Or how can I get access to an entity with that physics body to add a new component? like

var entityManager = Unity.Entities.World.DefaultGameObjectInjectionWorld.EntityManager;
entityManager.AddComponentData(new Entity() { Index = pb.Entity }, new PhysicsGraphicalSmoothing());
entityManager.AddComponentData(new Entity() { Index = pb.Entity }, new PhysicsGraphicalInterpolationBuffer
{
     PreviousTransform = Unity.Physics.Math.DecomposeRigidBodyTransform((float4x4)pb.transform.localToWorldMatrix),
     PreviousVelocity = new PhysicsVelocity(){ Linear = float3.zero, Angular = float3.zero},
 });

I am totally misunderstanding how it all works(

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions