This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cw4:tutorials:rotation_conversion [2021/01/09 14:38] – Sanian | cw4:tutorials:rotation_conversion [2025/02/14 14:57] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | <=[[cw4:scripting| Scripting]] | + | <=[[4rpl:start|Index]] \\ |
+ | < | ||
====== Converting between different kinds of rotation ====== | ====== Converting between different kinds of rotation ====== | ||
Line 11: | Line 12: | ||
===== Radians and degrees ===== | ===== Radians and degrees ===== | ||
- | {{ : | + | {{ : |
The trigonometry functions of 4RPL such as sin, cos, tan, atan2, etc. all use or return radian values, but other parts of the game use degrees, which is why you'll have to convert between them. | The trigonometry functions of 4RPL such as sin, cos, tan, atan2, etc. all use or return radian values, but other parts of the game use degrees, which is why you'll have to convert between them. | ||
Line 31: | Line 32: | ||
===== The difference between Unity rotation and mathematical rotation ===== | ===== The difference between Unity rotation and mathematical rotation ===== | ||
- | **TLDR; | + | **TLDR; |
- | Even though units are normally locked to the grid, the game allows us to rotate them by any amount. Lets try to give a unit a Y rotation of 30°, which should make them point slightly up and to the right just like the image of the section above. | + | Even though units are normally locked to the grid, the game allows us to rotate them by any amount. Lets try to give a unit a Y rotation of 30°, which should make them point slightly up and to the right, just like the image of the section above. |
<code 4rpl> | <code 4rpl> | ||
Line 40: | Line 41: | ||
</ | </ | ||
- | What we see when we run this however, is that the unit faces //down //and to the right instead, we only get the result we originally expected when we use the //negative //value -30°. This means that rotations along the Y-axis is inverted. It turns out the the same is true for the X-axis. The Z axis on the other hand is fine and works as we would expect. | + | What we see when we run this however, is that the unit faces //down //and to the right instead, we only get the result we originally expected when we use the //negative //value -30°. This means that rotations along the Y-axis is inverted. |
- | {{: | + | {{: |
- | So, if you work out some kind of angle within the map' | + | It turns out the the same is true for the X-axis (rotating by a negative value will make units face upwards instead of downwards). The Z axis on the other hand is not inverted and works as we would expect. |
+ | |||
+ | So, if you use conventional math to calculate a rotation | ||
+ | |||
+ | This way of calculating rotations is tied to the engine, and therefore used in any and all game objects that can have some kind of rotation. That includes units, their individual component objects and notably, the camera. | ||
---- | ---- | ||
Line 78: | Line 83: | ||
</ | </ | ||
- | <=[[cw4:scripting| Scripting]] | + | <=[[4rpl:tutorials| Tutorials]] |