View Single Post
  #1  
Old 05-13-2011, 10:13 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Vecx and Vecy Explained

Understanding vecx and vecy has been a common question for beginning scripters in GScript2. I wanted to make this post to help put some of those questions to rest.

On Graal, we use 4 directions: 0, 1, 2, 3 (up, left, down, right respectively). Put simply, the purpose of vecx(direction) and vecy(direction) is to give a change in x or y if an object were to move by 1 unit in the direction given.

So, for example, if your direction is 1 (that is, left), then vecx(1) = -1 because you would need to move -1 units in order to move left by 1 unit on the x-axis. Similarly, vecy(1) = 0 because if an object is moving left, then its y does not change.

Now we understand what values we should be receiving in different cases. I have outlined them here for you:


Now, we can solve for those values pretty easily using simple trigonometry.

If we refer to a complete circle, you may notice that on intervals of pi/2 we see the values of vecx and vecy we are trying to find.

So, using elementary trigonometry, we find vecx and vecy are actually:


Hope this helps.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote