Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. ///Apply Physics
  2. var speed_y,speed_x;
  3. //////////////////////
  4. ///Check for Y Axis///
  5. //////////////////////
  6.  
  7. if(delta_time_get_steady() *obj_velocity_y < global.gravity_max){
  8. obj_velocity_y += delta_time_get_steady() * global.gravity_force * 1000;
  9. }
  10.  
  11. //Get our current speed for this step on the y axis
  12. speed_y = delta_time_get_steady() * obj_velocity_y;
  13.  
  14. //Is our next position going to collide?
  15. if(place_meeting(x,y+speed_y,obj_wall)){
  16. //if so, add one pixel until we do collide
  17. while(!place_meeting(x,y+sign(speed_y),obj_wall)){
  18. y += sign(speed_y);
  19. }
  20. obj_velocity_y = 0;
  21. speed_y = 0;
  22. }
  23.  
  24. //apply calculated speed
  25. y = y + speed_y;
  26.  
  27.  
  28. //////////////////////
  29. ///Check for X Axis///
  30. //////////////////////
  31. //Add object acceleration
  32. obj_velocity_x += obj_accel_x;
  33.  
  34. //Get the current speed for this step on the x axis
  35. speed_x = delta_time_get_steady() * obj_velocity_x;
  36.  
  37.  
  38. //Keep in bounds on x axis
  39. if(place_meeting(x+speed_x,y,obj_wall)){
  40. while(!place_meeting(x + sign(speed_x),y,obj_wall)){
  41. x += sign(speed_x);
  42. }
  43. obj_velocity_x = 0;
  44. speed_x = 0;
  45. }
  46.  
  47. //Apply calculated speed
  48. x += speed_x;
  49.  
  50.  
  51. ////////////////////////////////
  52. ///Deaccelerate on the X Axis///
  53. ////////////////////////////////
  54. //if(place_meeting(x,y+1,obj_wall)){
  55. // obj_velocity_x = 0; // on ground so reset velocity
  56. //}else{
  57. // obj_velocity_x *= delta_time_get_steady() * 10; //
  58. //}
  59.  
  60. obj_velocity_x = floor(obj_velocity_x + -sign(obj_velocity_x) * ( delta_time_get_steady() * 1000));
  61. obj_accel_x = 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement