Skip to content

format

typescript
Vector3.RotateTowards(source, target, max_delta_radians, max_delta_mag)

class: Vector3

description

Rotates a game object from its current direction to a target direction.

The direction is similar to MoveTowards, but instead of representing the position of the object, it represents the direction. The game object will rotate from the source direction to the target direction. This method is useful for smoothly rotating between two vectors, commonly used for controlling the rotation direction of an object or achieving smooth turning effects.

parameter

param_nametypedescription
sourceVector3The current direction.
targetVector3The target direction.
max_delta_radiansnumberThe maximum number of radians the current vector can rotate.
max_delta_magnumberThe maximum size the current vector can scale.

return

typedescription
Vector3The rotated angle after the rotation.

code example

typescript
let lhs = new Vector3(1,2,3);
let rhs = new Vector3(3,4,5);
let v3_result =  Vector3.RotateTowards(lhs, rhs, 90, 1);
Debug.Log("add result is",v3_result);