User Tools

Site Tools


cw4:tutorials:rotation_conversion

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
cw4:tutorials:rotation_conversion [2021/01/09 21:08] – added image captions, phrasing. Saniancw4:tutorials:rotation_conversion [2025/02/14 14:57] (current) – external edit 127.0.0.1
Line 1: Line 1:
-<=[[cw4:scriptingScripting]]+<=[[4rpl:start|Index]] \\ 
 +<=[[cw4:Tutorials]]
  
 ====== Converting between different kinds of rotation ====== ====== Converting between different kinds of rotation ======
Line 31: Line 32:
 ===== The difference between Unity rotation and mathematical rotation ===== ===== The difference between Unity rotation and mathematical rotation =====
  
-**TLDR; Rotations along the X and Y axes are inverted.**+**TLDR; In Unity, rotations along the X and Y axes are inverted.**
  
-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 rightjust like the image of the section above.
  
 <code 4rpl> <code 4rpl>
Line 46: Line 47:
 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. 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 work out some kind of angle within the map'coordinate system and you want to to use that angle to modify unit in some way, make sure to invert the X and Y axes before doing so, or your unit will turn in exactly the opposite way. The easiest way to invert the X and Y angles of a vector is as follows: ''<-rotVector V3(-1 -1 1) * ->rotVector ''+So, if you use conventional math to calculate a rotation within the coordinate system of map, make sure to invert the X and Y axes of the rotation before applying it to a unit, or your unit will turn in exactly the opposite way. The easiest way to invert both X and Y values of a vector is as follows: ''<-rotVector V3(-1 -1 1) * ->rotVector''. For inverting a single value the [[4rpl:commands:neg]] function can be used.
  
 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. 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 82: Line 83:
 </code> </code>
  
-<=[[cw4:scriptingScripting]]+<=[[4rpl:tutorialsTutorials]]
  
  
cw4/tutorials/rotation_conversion.1610226507.txt.gz · Last modified: 2025/02/14 14:56 (external edit)