Here is a resource and a discussion.
How would you do this differently?
I <3 rocket science
import bgefrom mathutils import Vector
from math import cos, sin, sqrt, tan
def main():
cont = bge.logic.getCurrentController()
own = cont.owner
space = cont.sensors['Space']
if 'Helper' not in own:
own['Helper'] = own.scene.addObject('Helper',own,0)
own['Keep']= own.scene.objects['Keep']
if space.positive:
#create circle objects if they don't exist and jump is held
if 'C' not in own and own['Charge']>15:
own['C']=own.scene.addObject('Circle')
own['C2']=own.scene.addObject('Circle')
#Place jump object
rot = own.worldOrientation.to_euler()
rot.y += cos(3.14/4)
rot.x += cos(3.14/4)
rot = rot.to_matrix()
x = own['Keep']['y']*.1
y = own['Keep']['x']*.1
own['C2'].worldPosition = own.worldPosition+rot*Vector([x,y,-.995])
own['C2'].color = [1,0,0,1]
if own['Charge']<=99 and own['Time']==0:
own['Charge']+=1
own['Time']=1
V = .5+own['Charge']*.05
if own['Charge']>15 and 'C' in own:
own['C'].localScale = [V,V,1]
elif own['Charge']>15:
#jump state
d = own.getDistanceTo(own['C2'])
if d>0:
grav = 9.8*9.8
d2 = d*d
dz = own['C2'].worldPosition.z
angle = 3.14/4
v0 = (1 / cos(angle)) * sqrt((0.5 * grav* d2) / (d * tan(angle) + dz))
v2 = own.getVectTo(own['C2'].worldPosition)
own['Helper'].alignAxisToVect([0,0,1],2,1)
own['Helper'].alignAxisToVect(v2[1],0,1)
rot = own['Helper'].worldOrientation.to_euler()
rot.y-=3.14/4
rot = rot.to_matrix()
own['Helper'].worldOrientation = rot
p= own['Helper'].worldPosition+rot*Vector([1,0,0])
v2 = own.getVectTo(p)
own.applyForce(own['Helper'].worldOrientation.col[0]*v0*9.8*2,0)
if 'C' in own:
own['C'].endObject()
del own['C']
if 'C2' in own:
own['C2'].removeParent()
del own['C2']
own['Charge']=0
pass
elif own['Charge']<15:
own['Charge']=0
if 'C2' in own:
rot = own.scene.objects['Camera'].worldOrientation.to_euler()
rot.y += 3.14/2
rot.z += 3.14/4
rot = rot.to_matrix()
x = -own['Keep']['y']*.1
y = own['Keep']['x']*.1
if abs(x)>(own['Charge']*.05):
if x<0:
x = -own['Charge']*.05
own['Keep']['y'] = own['Charge']/2
else:
x = own['Charge']*.05
own['Keep']['y'] = -own['Charge']/2
if abs(y)>(own['Charge']*.05):
if y<0:
y = -own['Charge']*.05
own['Keep']['x'] = -own['Charge']/2
else:
y = own['Charge']*.05
own['Keep']['x'] = own['Charge']/2
own['C2'].worldPosition = own.worldPosition+rot*Vector([0,y,x])
main()