Advertisement
rooksword

Vec2 script

Nov 5th, 2022 (edited)
3,061
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Vec2(_x = 0, _y = 0) constructor
  2. {
  3.     x = _x;
  4.     y = _y;
  5.    
  6.     function Add(_v)
  7.     {
  8.         x += _v.x;
  9.         y += _v.y;
  10.     }
  11.    
  12.     function AddT(_t)
  13.     {
  14.         x += _t;
  15.         y += _t;
  16.     }
  17.    
  18.     function Multiply(_v)
  19.     {
  20.         x *= _v.x;
  21.         y *= _v.y;
  22.     }
  23.    
  24.     function MultiplyT(_t)
  25.     {
  26.         x *= _t
  27.         y *= _t;
  28.     }
  29.    
  30.     function Lerp(_v, _acc)
  31.     {
  32.         x = lerp(x, _v.x, _acc);
  33.         y = lerp(y, _v.y, _acc);
  34.     }
  35.    
  36.     function Rotate(_a)
  37.     {
  38.         var _xc = x * cos(_a);
  39.         var _ys = y * sin(_a);
  40.         var _xs = x * sin(_a);
  41.         var _yc = y * cos(_a);
  42.        
  43.         x = _xc - _ys;
  44.         y = _xs + _yc;
  45.     }
  46.    
  47.     function Lengthdir(_dir)
  48.     {
  49.         x = lengthdir_x(x, _dir);
  50.         y = lengthdir_y(y, _dir);
  51.     }
  52.    
  53.     function Magnitude()
  54.     {
  55.         return sqrt(sqr(x) + sqr(y));  
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement