Search Unity

Question ApplyAngularImpulse around a point

Discussion in 'Physics for ECS' started by slushieboy99, Oct 7, 2022.

  1. slushieboy99

    slushieboy99

    Joined:
    Aug 29, 2014
    Posts:
    88
    Hi all, I'm trying to apply an angular impulse not around the center of mass, but around a different point. Does anyone know the math to make this work?

    I found @steveeHavok replied to this thread with some answers, but I'm having trouble getting that code to work. I don't know if ApplyAngularImpulse is now in world space instead of inertia space, but I have success rotating around the center of mass just fine until I implement this code (with point set to (0,0,0)) and get very unexpected behavior and spinning.

    Below is my current code which rotates around the center of mass. I'm essentially trying to keep certain entities upright.

    Code (CSharp):
    1. quaternion upQuat = QuaternionFunctions.FromToRotation(ltw.Up, new float3(0, 1, 0));
    2.                 float3 upVec = upQuat.value.xyz;
    3.                 float force = physicsParams.keepUprightAcceleration * (1 / physicsMass.InverseMass);
    4.                 float3 dirVec = upVec * force * deltaTime;
    5.                 Debug.Log(dirVec);
    6.  
    7.                 physicsVelocity.ApplyAngularImpulse(physicsMass, dirVec);
     
    Last edited: Oct 7, 2022