#How to rotate to look at a direction with PhysicsVelocity?

1 messages · Page 1 of 1 (latest)

muted mesa
#

I've got my quaternion
quaternion.LookRotationSafe(math.normalize(destination), math.up());

I found this code online but, I don't have access to "Quaternion.FromToRotation"
var rotation = Quaternion.FromToRotation(currentDirection, targetDirection).eulerAngles * sensitivity;
rigidbody.angularVelocity = rotation;

muted mesa
#

neither do i have access to ".eulerAngles"

digital spindle
#

I recommend taking a look at the implementation of PhysicsVelocity.CalculateVelocityToTarget, it might show you what you need 😄

#

Here's the interesting part for you:

var worldFromBody = new RigidTransform(bodyOrientation, bodyPosition);
var worldFromMotion = math.mul(worldFromBody, bodyMass.Transform);
var motionFromWorld = math.inverse(worldFromMotion.rot);
var angularVelocity = math.mul(targetTransform.rot, math.inverse(worldFromBody.rot)).ToEulerAngles() * stepFrequency;
requiredAngularVelocity = math.rotate(motionFromWorld, angularVelocity);
#

Where bodyOrientation and bodyPosition is your current pos and rotation. targetTransform.rot is your desired rotation (you can replace this with a quaternion using something like quaternion.LookRotation(...))
stepFrequency is 1/FixedDeltaTime. bodyMass.Transform is well, your PhysicsMass.Transform :3

muted mesa
#

ok i will be experimenting with this. TY

digital spindle
#

No clue if it helps in your sittuation, but as they say 'discovery requires experimentation' 😛