Skip to content

format

typescript
Quaternion.FromToRotation(from_dir, to_dir)

class: Quaternion

description

Creates a quaternion that rotates from the direction specified by from_dir to the direction specified by to_dir.

Typically, you use this method to rotate a transform so that one of its axes (e.g., the Y-axis) aligns with a target direction in world space.

parameter

param_nametypedescription
from_dirQuaternionThe quaternion representing the initial direction.
to_dirQuaternionThe quaternion representing the target direction.

return

typedescription
QuaternionThe new quaternion.

code example

typescript
function QuaternionTest (){
    let identity = Quaternion.identity;
    let quat_axis = Quaternion.AngleAxis(60, new Vector3(0,1,0));
    let from = Quaternion.FromToRotation(identity, quat_axis);
}