Advertisement
Guest User

Slope Code

a guest
Jan 14th, 2018
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Code for determining most, if not all of the core physics.
  2.  
  3. var incomingobject = instance_place(wherex, wherey, obj_Phys_Object);
  4. //Setting a variable to whatever it is you are GOING to hit, based on your speed and location.
  5.  
  6. var tick = 0;
  7. //This variable will be counted up later to determine how wide of an angle the game can check reletive to your current angle.
  8. //Just a basic counter, I think this might actually be redundant?
  9.  
  10. var tickcounter = 15 / (phys_priority/5);
  11. //At the beginning of this script, the base tick counter is set to 15, before anything else.
  12.  
  13. var startangle = point_direction(x, y, wherex, wherey);
  14. //The angle this script starts with.
  15. //It checks where you are, where you are going to be (based on your speeds and location)
  16. //Then it returns the angle of that.
  17.  
  18. var startdistance = point_distance(x, y, wherex, wherey);
  19. //The distance this script starts with.
  20. //Again, where you are, where you are going to be, and the distance between those.
  21.  
  22. if incomingobject != noone
  23. //If you are about to hit an object, based on your speed and direction
  24. {
  25.     if incomingobject.stable = true
  26.     //If you are about to hit an object that is stable
  27.     {
  28.         tickcounter = clamp(tickcounter*0.8, 0, 15);
  29.         //Make the angle stricter for how far the game can alter your direction.
  30.         //This improves platforming, since you can use stable objects for platforming and restricting the player.
  31.     }
  32.    
  33.     var platformwherex = x + incomingobject.hsp + incomingobject.movinghsp
  34.     var platformwherey = y + incomingobject.vsp + incomingobject.movingvsp
  35.    
  36.     if place_meeting(wherex, wherey, incomingobject)
  37.     {
  38.         if !place_meeting(platformwherex, y, obj_Phys_Object) && inert = false
  39.         {
  40.             if incomingobject.movinghsp = 0
  41.             {
  42.                 x += incomingobject.hsp
  43.                 movinghsp = incomingobject.hsp
  44.             }
  45.             else
  46.             {
  47.                 x += incomingobject.movinghsp
  48.                 movinghsp=incomingobject.movinghsp
  49.             }
  50.         }
  51.        
  52.         if !place_meeting(x, platformwherey, obj_Phys_Object) && inert = false
  53.         {
  54.             if incomingobject.onground = false
  55.             {
  56.                 y += incomingobject.vsp
  57.                 movingvsp=incomingobject.vsp
  58.             }
  59.             else
  60.             {
  61.                 y += incomingobject.movingvsp
  62.                 movingvsp=incomingobject.movingvsp
  63.             }
  64.         }
  65.        
  66.  
  67.        
  68.         if incomingobject.inert != true && !place_meeting(x, y+5, incomingobject)
  69.         {
  70.             incomingobject.hsp = (hsp+incomingobject.hsp+movinghsp)
  71.             incomingobject.vsp = (vsp+incomingobject.vsp+movingvsp)
  72.            
  73.             if onground = false
  74.             {
  75.                 incomingobject.movinghsp = hsp
  76.             }
  77.             else
  78.             {
  79.                 incomingobject.movinghsp = movinghsp
  80.             }
  81.            
  82.             if onground = false
  83.             {
  84.                 incomingobject.movingvsp = vsp
  85.             }
  86.             else
  87.             {
  88.                 incomingobject.movingvsp = movingvsp
  89.             }
  90.            
  91.         }
  92.     }
  93. }
  94.  
  95. if startangle > 230 && startangle < 300 && vsp < 30
  96. //If you are going NEARLY directly down
  97. {
  98.     tickcounter = clamp(tickcounter*0.4, 0, 15);
  99.     //Make the angle stricter for how far the game can alter your direction.
  100.     //WITHOUT THIS, WEIRD SHIT HAPPENS ALL THE TIME
  101. }
  102.  
  103. if abs(vsp) < 1
  104. //If you aren't moving very fast at all up or down
  105. {
  106.     tickcounter = clamp(tickcounter*2, 0, 15);
  107.     //Make the angle less strict for how far the game can move you.
  108.     //WITHOUT THIS, WEIRD SHIT HAPPENS ALL THE TIME
  109. }
  110.  
  111. if abs(vsp) < abs(hsp)
  112. {
  113.     tickcounter = clamp(tickcounter*2, 0, 15);
  114. }
  115.  
  116. for (var tick = 0; tick <= tickcounter; tick ++)
  117. //while tick <= tickcounter
  118. //The game can only check a limited number of angles near your own, based on the tick counter.
  119. {  
  120.     if (tick % 2) == 0
  121.     //Every other tick (I don't understand how this snippet of code works.
  122.     //but it does.
  123.     {
  124.         newangle = startangle + (tick*phys_priority);
  125.         //Check an angle equal to yours plus the current tick times 5.
  126.         //So each tick it checks an angle further away.
  127.     }
  128.     else
  129.     {
  130.         newangle = startangle - (tick*phys_priority);
  131.         //Every OTHER angle though, check your angle MINUS the current tick times 5.
  132.         //So it checks to the left and right of where you are going
  133.     }
  134.  
  135.     finalhsp = lengthdir_x(startdistance, newangle)
  136.     //Your final horizontal speed after this script will be based on your original speed and your new angle
  137.  
  138.     finalvsp = lengthdir_y(startdistance, newangle)
  139.     //Same thing with your vertical speed.
  140.    
  141.     finallocationx = x+finalhsp;
  142.     //Your final position after calculations complete will be based on your current position and your new speed.
  143.  
  144.     finallocationy = y+finalvsp;
  145.     //Same thing with the vertical coordinate.
  146.    
  147.     if !place_meeting(finallocationx, finallocationy, obj_Phys_Object)
  148.     {
  149.         speedreduction = abs(angle_difference(newangle, startangle))
  150.        
  151.         speedreduction = speedreduction/180.0;
  152.    
  153.         speedreduction = 1.0-speedreduction;
  154.  
  155.         speedreduction = sqr(speedreduction);
  156.  
  157.         show_debug_message(current_time);
  158.         x = finallocationx
  159.         y = finallocationy
  160.         hsp = ((finalhsp*speedreduction)+(finalhsp*3))/4
  161.         vsp = ((finalvsp*speedreduction)+(finalvsp*3))/4
  162.         break;
  163.     }
  164.     else
  165.     {
  166.     hsp = hsp*0.99
  167.     vsp = yourgravity
  168.     }
  169. }
  170.  
  171. if place_meeting(x, y, obj_Phys_Object)
  172. {
  173.     vsp -= abs(hsp*0.7);
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement