User Tools

Site Tools


4rpl:commands:rotatetowards

Index
Math Utility

RotateTowards

RotateTowards(<-startDir <-targetDir <-maxDegrees) ->newDir

Description

  • startDir: The directional vector to start at.
  • targetDir: The directional vector to end up at.
  • maxDegrees: The maximum amount of degrees the start direction will rotate towards the target direction.
  • newDir: The new directional vector (normalized).

A directional vector is defined as a line drawn from the origin (0, 0, 0) to a coordinate at the xyz values of the vector. This means 4 dimensional vectors are not supported. The magnitude of the vector (distance from origin to point) is ignored.

The startDir vector will be rotated round toward the targetDir by an angle of maxDegrees, although it will land exactly on the target rather than overshoot. If a negative value is used for maxDegrees, the vector will rotate away from targetDir until it is pointing in exactly the opposite direction, then stops.

The resulting vector newDir is normalized, meaning its magnitude will always be exactly 1. Inputting targetDir (1, 1, 1) and successfully rotating towards it will therefore output (0.5773503, 0.5773503, 0.5773503), not (1, 1, 1).

Examples

RotateTowards(V3(1 0 0) V3(1 1 1) 10) ->vec

Index

4rpl/commands/rotatetowards.txt · Last modified: 2022/09/04 09:28 by Karsten75