Advertisement
Guest User

warp_movement_entity [fix for my game]

a guest
Nov 21st, 2018
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///warp_movement_entity(xwarp, ywarp)
  2. /*
  3.     This script can be used to warp a movement or solid entity
  4.     to a location while keeping that instance outside of any
  5.     collision objects.
  6. */
  7.  
  8. var xwarp = argument0; // x position to warp to
  9. var ywarp = argument1; // y position to warp to
  10. var xdif = xwarp - x;
  11. var ydif = ywarp - y;
  12.  
  13. if (place_meeting(xwarp, ywarp, solids)) {
  14.     var ang = arctan(ydif / xdif);
  15.     var cosang = cos(ang);
  16.     var sinang = sin(ang);
  17.     var dist = distance_to_point(xwarp, ywarp);
  18.     var hasMidpoint = false;
  19.    
  20.     while(!hasMidpoint && dist >= 0) {
  21.         xdif -= cosang;
  22.         ydif += sinang;
  23.         dist--;
  24.        
  25.         if (!place_meeting(x + xdif, y + ydif, solids)) {
  26.             x += xdif;
  27.             y += ydif;
  28.             hasMidpoint = true;
  29.         }
  30.     }
  31. } else {
  32.     x = xwarp;
  33.     y = ywarp;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement