Unity from Proficiency to Mastery (C# Programming): Master C# with Unity by Patrick Felicia

Unity from Proficiency to Mastery (C# Programming): Master C# with Unity by Patrick Felicia

Author:Patrick Felicia [Felicia, Patrick]
Language: eng
Format: azw3
Published: 2017-10-29T04:00:00+00:00


Now that we have clarified the calculation of the cosine, let’s explain how we can find the vectors V1 and V2. V1 is the forward direction for the NPC. This vector originates (on the diagram) from the NPC and is going in the direction of the positive z-axis. V2 is determined by the position of both the NPC and the player.

Let’s see how: as you can see on the next diagram, the vectors V2, Vnpc and Vplayer form a triangle. Vnpc is the vector for the position of the NPC and it starts at the origin of the coordinate system. Vplayer is the vector for the position of the NPC and, as for the previous vector, it starts at the origin of the coordinate system. If we operate a clockwise loop from the origin of the coordinate system, we can go from the origin of the coordinate system to the NPC by following the vector Vnpc, then follow the vector V2 (from its tail to its head), and then follow the vector Vplayer in reverse (that is, from its head to its tail; this is the same as -Vplayer) to be back to the origin of the coordinate system. So we could say that: Vnpc + V2-Vplayer = 0; in other words, by following Vnpc, then V2, and then Vplayer in reverse, we end up at the same point. Following this, we can then say that: V2 = -Vnpc + Vplayer (we just added -V2 to both sides of the previous equation) and this is how we can calculate V2.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.