Advertisement
Guest User

Collision Code

a guest
Sep 7th, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var hsp_final = hsp + hsp_carry;
  2. hsp_carry = 0;
  3.  
  4. var vsp_final = vsp + vsp_carry;
  5. vsp_carry = 0;
  6.  
  7.  
  8. scrCollide(round(hsp_final), round(vsp_final), par_wall); //First bit is argument0, second is 1 and par_wall is argument2
  9. x = round(x); y = round(y);
  10.  
  11. ///scrCollide
  12. //This script calculates the exact position of the player in the world and is designed to be used with moving platforms.
  13. {
  14.  //argument0 - x displacement
  15.  //argument1 - y displacement
  16.  //argument2 - wall parent
  17.  
  18.  var i,move_check; //Defines Variables
  19.  
  20.  for (i = abs(argument0)/* hsp_final */; i > 0; /*As soon as i is greater or less than 0, it will stop looping*/ i -= 1)
  21.  {
  22.   if (i < 0) {i = 0;}
  23.   move_check = sign(argument0)*i; //Returns if the number is positive, negative or 0, then multiplies that by 1, seeing if the movement is left or right
  24.  
  25.   if !(place_meeting(x+move_check,y,argument2))//If not moving into par_wall in either direction
  26.   {
  27.     if instance_exists(obj_rock_crush){
  28.         if !(place_meeting(x+move_check,y,obj_rock_crush)){
  29.         x += move_check; //Then move
  30.         break;
  31.    }
  32.   }
  33.  }
  34.       /*If I haven't hit an obstacle, then it must be safe to move this distance, so I'll move, and then stop the loop because I don't need to check any more'.*/
  35. }
  36.  
  37.  for (i = abs(argument1); i > 0; i -= 1)
  38.  {
  39.  
  40.   if (i < 0) {i = 0;}
  41.   move_check = sign(argument1)*i; //Returns if the number is positive, negative or 0
  42.  
  43.   if !(place_meeting(x,y+move_check,argument2))
  44.   {
  45.    y += move_check; //The same as above only for verticle movement
  46.    break;
  47.   }
  48.  
  49.   if !(place_meeting(x-i,y+move_check,argument2)) //If moving upwards, both pieces of code checks to see if par_wall is anywhere diagnolly to the left or right of you
  50.    x -= i/2;
  51.  
  52.   if !(place_meeting(x+i,y+move_check,argument2)) //If there isn't anything to the left orright, then the player scootches a bit to the left or right i/2
  53.    x += i/2; //In other words, most of the time, your player is constantly scooching left and right. But because the two cancel each other out, the combined motion is always zero.
  54.   //If there IS something to the left of you, your player won't scooch in that direction - which means the overall amount of scooching will be to the right.
  55.  }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement