Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //returns the angle between two vectors
- function angleBetween(%v1, %v2)
- {
- //cos(theta) = (v1*v2)/(|v1|*|v2|)
- //theta = arccos(cos(thetha))
- return mAcos(VectorDot(%v1, %v2)/(VectorLen(%v1)*VectorLen(%v2)));
- }
- //only use x, y components since we're working on a 2D plane
- %v1 = getWords(%player.getPosition(), 0, 1);
- %v2 = getWords(%puck.getPosition(), 0, 1);
- %lookVector = vectorSub(%v2, %v1); //vector that points from %v1 to %v2 with length |%v2-%v1|
- %angle = angleBetween(%player.getForwardVector(), %lookVector);
- //%theta being some acceptable view-bounds angle
- //0 would mean looking right at the puck's position
- //pi would mean looking anywhere
- if(%angle <= %theta)
- {
- //...
- }
- //takes 2D vector %v and returns the closest global axis-locked vector
- function alignVector(%v)
- {
- %x = getWord(%v, 0);
- %y = getWord(%v, 1);
- %sx = %x < 0 ? -1 : 1;
- %sy = %y < 0 ? -1 : 1;
- if(mAbs(%x) >= mAbs(%y))
- %vec = %sx SPC "0";
- else
- %vec = "0" SPC %sy;
- return %vec;
- }
- //say a player is looking mainly eastward
- alignVector(%player.getForwardVector()) -> "1 0"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement