Quaternion Euler rotation on rigid body

Unity has a Euler method on their Quaternion class. According to the docs it takes a Vector3 as an argument and returns a rotation in the form of a Quaternion. Since Unity’s Rigidbody.rotation is also a Quaternion you can do something simple like:

GetComponent<Rigidbody>().rotation = Quaternion.Euler(0, 0, -5);

What would be the equivalent operation on a PlayCanvas entity that has a rigid body component?

The rigidbody has a teleport function that allows you to set the position and rotation (euler or quaternion) of the rigidbody. https://developer.playcanvas.com/en/api/pc.RigidBodyComponent.html#teleport

The Quat class also has a setFromEulerAngles: https://developer.playcanvas.com/en/api/pc.Quat.html#setFromEulerAngles

1 Like

So I could do something like that?:

var newRotation = new pc.Quat().setFromEulerAngles(0, 0, -5);
this.entity.rigidbody.teleport(newPosition, newRotation);

Yep, or:

this.entity.rigidbody.teleport(newPosition, new pc.Vec3(0, 0, -5));
1 Like