Created Frame (markdown)

bi0qaw 2017-11-22 23:08:20 +01:00
parent b30e52c350
commit ff18155ec3

33
Frame.md Normal file

@ -0,0 +1,33 @@
Frames are used whenever you want to change the direction of a bunch of vectors. Instead of rotating the list of vectors you can just grab a frame and let it do the correct rotations. This is best shown with a small example:
![](https://i.imgur.com/ObIhdQz.png?1) ![](https://i.imgur.com/iWdfVQ2.png?1)
The two images show each a player with a particle circle around his head. The nice thing is that the particle circle follows the rotation of the player's head. To reproduce this effect you can execute the following script:
```
command /halo:
trigger:
set {_frame} to frame of player
set {_circle::*} to circle with radius 1 and density 5
set {_rotated-circle::*} to {_circle::*} in {_frame}
set {_circle-locations::*} to location 1 above player's head offset by {_rotated-circle::*}
show happy villager at {_circle-locations::*}
```
All the magic happens in lines 3 and 5. In line 3 we grab the frame of the player and in line 5 we rotate our vectors with the frame. A frame is nothing else than a mini coordinate-system that stores the orientation of an entity. The expression `%vectors% in %frame%` just tells Skript to use the coordinate system of the frame instead of the standard Minecraft coordinate system. This is illustrated by the following picture where the flame particles indicate the three axes of the frame.
![](https://i.imgur.com/lDHaMOm.png)
You can see that the circle is still in the "*horizontal*" XZ-plane but the whole coordinate system is rotated. This is basically everything you have to know about frames.
## When should I use frames?
* When you need the same shape in multiple directions
* When you need to update the direction of a shape over and over again
* When you need to rotate a lot of points
* When it is more convenient to you
Note that frames do not completely replace rotations. I tend to use rotations during the creation stage of a shape and then get the final orientation with a frame. Let's illustrate this with the example of the circle around the player's head. What if want a circle that goes vertically around the player's head and not horizontally? It is possible to achieve this with frames only but you will have to deal with a lot of annoying yaw/pitch problems. The solution to this is that you first get a vertical circle and then show it in the frame of the player:
```
set {_circle::*} to circle with radius 1 and density 5 # Creates a circle in the horizontal XZ-plane
set {_circle::*} to {_circle::*} rotated around z-axis by 90 # Rotate the circle to a vertical position
show happy villager at location 1 above player's head offset by {_circle::*} in frame of player # show the particles
```