wrote this in python as a draft and plan to convert it to c# once it's done since the most convenient console I had for experimenting with things like this was python
so I made this script to calculate the vertical trajectory of an object thrown at velocity velocity. it's a little hacky but it works fine.
problem is I need velocity as an output, not an input, since I need this for a spring which will attempt to launch the player toward a certain height, adjusting for forces like gravity over time.
velocity = 10
gravity = 2
iterations = 5*gravity
def sumFromZero(number):
number /= gravity
number = number*(number+1)/2
number *= gravity
return number
def calculateTrajectory(number):
number += 1
return sumFromZero(velocity)-sumFromZero(velocity-number)
print("============================")
for i in range(iterations):
if (i+1)%gravity<0.01:
print(calculateTrajectory(i)-calculateTrajectory(i)%1)
best solution I could think of was to convert this into a mathematical function and just use algebra to move velocity to the other side of the equation, but I'm not sure exactly how to do that.
anyone able to assist?