2D Based GUI Jumping

As some may know i’m a bit of a Desmos nerd. :blush: With that being said I developed a way with just solving some equations to make 2d jump physics, usually we would just angle the camera and then use a 3d based 2d system but I beg to differ. We first need to make sure are player doesn’t fall out so what we will do is basically check where their future state will be based on their current movement (the rate of change, slope in other words of their x position). We basically see where they will be in the next frame by using aabb logic if they are we will set their “velocity” or in other words the rate of change in pixels to 0. Now that we have a mover and a way to stop us from going into the void lemme explain how this works

The quadratic formula has 4 variables, that being a, how spacey are jump should be in a sense and b being our jump force in a sense. There is also c and x however c is irrelevant for our case and x is simply a time step of sorts. We define a, the gravity of the system to be 4 times how high we want to go over how long we want to go squared. Why? This is found from the vertex formula, it’s really just a case of system of equations. Will then define that b is equivalent to 2 times the square root of our height times our gravity. Again, just solving systems of equations. We need to wrap our time step, that being 0 to t to a range form 0 to 1. Now we can’t just use a sigmoid or the hyperbolic tangent. We need a linear conversion. To do that will use my Math++ modules bound() function. It basically, again is just solving a system of equations for the lerp function. From there we will set k to be our alpha of our lerp. Now we can stop here but I am sure some of you want to expand this from just 2D and use this for example, making a rocket launch. To angle are rocket ship we first want to find the slope of what is known as the “derivative”. To do this we can use my Math++ module again, passing in our value of k when it is NOT bounded and our dx, in a sense how small dx is the more accurate the derivative will be but will take longer to calculate and our function, returning the quadratic we gave it. With this new found slope will use the point slope formula to get 2 points on that derivative. From there we will use this neat cframe trick I found from @IFthenElse246 by doing

local part = Instance.new("Part", game.Workspace)
part.CFrame = CFrame.new((pos1 + pos2) / 2, pos1)
part.Size = Vector3.new(0.5, 0.5, x)

where pos1 refers to the head of our vector and pos2 refers to the tail. We will then transpose our CFrame rotation to the rocket ship. Have fun. :slight_smile:

image

11 Likes