Advertisement
Guest User

reflected vector script

a guest
Jun 22nd, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @function get_reflected_vector(cx, cy, incidence_direction, collision_object)
  2. ///@description Returns the direction of a reflected vector based on the direction of an incidence vector
  3. ///@param {real} cx | Collision x to check for.
  4. ///@param {real} cy | Collision y to check for.
  5. ///@param {real} incidence_direction | Direction of incidence vector.
  6. ///@param {real} collision_object | The instance id to check for collisions with.
  7.  
  8. #region More Info
  9. /*
  10.     Given the angle incidence, calculates reflected vector direction based on
  11.     surface normal of collision object
  12. */
  13. #endregion
  14.  
  15. var n, nx, ny, ix, iy, rx, ry;
  16. var cx = argument0;
  17. var cy = argument1;
  18. var i_dir = argument2;
  19. var obj = argument3;
  20.  
  21. // Find surface normal
  22. n = collision_normal(cx, cy, obj_solid, 7.5, 1);
  23. nx = lengthdir_x(1, n);
  24. ny = lengthdir_y(1, n);
  25.    
  26. // Find incident vector
  27. ix = lengthdir_x(1, i_dir);
  28. iy = lengthdir_y(1, i_dir);
  29.    
  30. // Find reflection vector
  31. rx = ix - 2 * nx * dot_product(ix, iy, nx, ny);
  32. ry = iy - 2 * ny * dot_product(ix, iy, nx, ny);
  33.    
  34. // Find reflection angle
  35. return point_direction(0, 0, rx, ry);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement