Next revision | Previous revision |
4rpl:commands:rotatetowards [2021/01/08 16:01] – external edit 127.0.0.1 | 4rpl:commands:rotatetowards [2025/02/14 14:57] (current) – external edit 127.0.0.1 |
---|
~~NOTOC~~ | <=[[4rpl:start| Index]] \\ |
<=[[4rpl:start| Index]] | <=[[4rpl:start#math_utility| Math Utility]] |
| |
====== RotateTowards ====== | ====== RotateTowards ====== |
RotateTowards(<-start <-target <-maxDegrees) ->vec | |
| RotateTowards(<-startDir <-targetDir <-maxDegrees) ->newDir |
| |
===== Description ===== | ===== Description ===== |
Rotates a start vector (x,y,z) towards a target vector (x,y,z). Will not move more than maxDegrees. The resulting vector is pushed to the stack as a float of three floats. | |
Each vector is treated as a direction rather than a position and is treated as having 3 values. So 4 dimensional vectors are not supported. | * **startDir**: The directional vector to start at. |
If negative maxDegrees is specified, the result is a vector that rotates away from the target vector. | * **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 ===== | ===== Examples ===== |
| |
<code 4rpl> | <code 4rpl> |
RotateTowards(V3(1 0 0) V3(1 1 1) 10) ->vec | RotateTowards(V3(1 0 0) V3(1 1 1) 10) ->vec |
</code> | </code> |
| |
<=[[4rpl:start| Index]] | <=[[4rpl:start| Index]] |
| |
| ~~NOTOC~~ |
| |