Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Code for determining most, if not all of the core physics.
- var incomingobject = instance_place(wherex, wherey, obj_Phys_Object);
- //Setting a variable to whatever it is you are GOING to hit, based on your speed and location.
- var tick = 0;
- //This variable will be counted up later to determine how wide of an angle the game can check reletive to your current angle.
- //Just a basic counter, I think this might actually be redundant?
- var tickcounter = 15 / (phys_priority/5);
- //At the beginning of this script, the base tick counter is set to 15, before anything else.
- var startangle = point_direction(x, y, wherex, wherey);
- //The angle this script starts with.
- //It checks where you are, where you are going to be (based on your speeds and location)
- //Then it returns the angle of that.
- var startdistance = point_distance(x, y, wherex, wherey);
- //The distance this script starts with.
- //Again, where you are, where you are going to be, and the distance between those.
- if incomingobject != noone
- //If you are about to hit an object, based on your speed and direction
- {
- if incomingobject.stable = true
- //If you are about to hit an object that is stable
- {
- tickcounter = clamp(tickcounter*0.8, 0, 15);
- //Make the angle stricter for how far the game can alter your direction.
- //This improves platforming, since you can use stable objects for platforming and restricting the player.
- }
- var platformwherex = x + incomingobject.hsp + incomingobject.movinghsp
- var platformwherey = y + incomingobject.vsp + incomingobject.movingvsp
- if place_meeting(wherex, wherey, incomingobject)
- {
- if !place_meeting(platformwherex, y, obj_Phys_Object) && inert = false
- {
- if incomingobject.movinghsp = 0
- {
- x += incomingobject.hsp
- movinghsp = incomingobject.hsp
- }
- else
- {
- x += incomingobject.movinghsp
- movinghsp=incomingobject.movinghsp
- }
- }
- if !place_meeting(x, platformwherey, obj_Phys_Object) && inert = false
- {
- if incomingobject.onground = false
- {
- y += incomingobject.vsp
- movingvsp=incomingobject.vsp
- }
- else
- {
- y += incomingobject.movingvsp
- movingvsp=incomingobject.movingvsp
- }
- }
- if incomingobject.inert != true && !place_meeting(x, y+5, incomingobject)
- {
- incomingobject.hsp = (hsp+incomingobject.hsp+movinghsp)
- incomingobject.vsp = (vsp+incomingobject.vsp+movingvsp)
- if onground = false
- {
- incomingobject.movinghsp = hsp
- }
- else
- {
- incomingobject.movinghsp = movinghsp
- }
- if onground = false
- {
- incomingobject.movingvsp = vsp
- }
- else
- {
- incomingobject.movingvsp = movingvsp
- }
- }
- }
- }
- if startangle > 230 && startangle < 300 && vsp < 30
- //If you are going NEARLY directly down
- {
- tickcounter = clamp(tickcounter*0.4, 0, 15);
- //Make the angle stricter for how far the game can alter your direction.
- //WITHOUT THIS, WEIRD SHIT HAPPENS ALL THE TIME
- }
- if abs(vsp) < 1
- //If you aren't moving very fast at all up or down
- {
- tickcounter = clamp(tickcounter*2, 0, 15);
- //Make the angle less strict for how far the game can move you.
- //WITHOUT THIS, WEIRD SHIT HAPPENS ALL THE TIME
- }
- if abs(vsp) < abs(hsp)
- {
- tickcounter = clamp(tickcounter*2, 0, 15);
- }
- for (var tick = 0; tick <= tickcounter; tick ++)
- //while tick <= tickcounter
- //The game can only check a limited number of angles near your own, based on the tick counter.
- {
- if (tick % 2) == 0
- //Every other tick (I don't understand how this snippet of code works.
- //but it does.
- {
- newangle = startangle + (tick*phys_priority);
- //Check an angle equal to yours plus the current tick times 5.
- //So each tick it checks an angle further away.
- }
- else
- {
- newangle = startangle - (tick*phys_priority);
- //Every OTHER angle though, check your angle MINUS the current tick times 5.
- //So it checks to the left and right of where you are going
- }
- finalhsp = lengthdir_x(startdistance, newangle)
- //Your final horizontal speed after this script will be based on your original speed and your new angle
- finalvsp = lengthdir_y(startdistance, newangle)
- //Same thing with your vertical speed.
- finallocationx = x+finalhsp;
- //Your final position after calculations complete will be based on your current position and your new speed.
- finallocationy = y+finalvsp;
- //Same thing with the vertical coordinate.
- if !place_meeting(finallocationx, finallocationy, obj_Phys_Object)
- {
- speedreduction = abs(angle_difference(newangle, startangle))
- speedreduction = speedreduction/180.0;
- speedreduction = 1.0-speedreduction;
- speedreduction = sqr(speedreduction);
- show_debug_message(current_time);
- x = finallocationx
- y = finallocationy
- hsp = ((finalhsp*speedreduction)+(finalhsp*3))/4
- vsp = ((finalvsp*speedreduction)+(finalvsp*3))/4
- break;
- }
- else
- {
- hsp = hsp*0.99
- vsp = yourgravity
- }
- }
- if place_meeting(x, y, obj_Phys_Object)
- {
- vsp -= abs(hsp*0.7);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement