Hi, I am learning Python after a very long break from Blender, I am having a problem, how would I make my player jump when spacebar is pressed and the player is touching the ground? I can do this easily using logic bricks via rays or collision, but not so easily with Python, I would like to learn how to do this with Python.
Here is my .blend: http://www.pasteall.org/blend/34039 (0.5mb)
Here is the code being used:
import bge
def main():
cont = bge.logic.getCurrentController()
player = cont.owner
keyboard = bge.logic.keyboard
if bge.logic.KX_SENSOR_ACTIVE == keyboard.events[bge.events.WKEY]:
player.applyMovement((0,.1,0), True)
if bge.logic.KX_SENSOR_ACTIVE == keyboard.events[bge.events.SKEY]:
player.applyMovement((0,-.1,0), True)
if bge.logic.KX_SENSOR_ACTIVE == keyboard.events[bge.events.AKEY]:
player.applyRotation((0,.0,.05), True)
if bge.logic.KX_SENSOR_ACTIVE == keyboard.events[bge.events.DKEY]:
player.applyRotation((0,0,-.05), True)
if bge.logic.KX_SENSOR_JUST_ACTIVATED == keyboard.events[bge.events.SPACEKEY]:
player.applyForce((0,0,400), True)
#What I want:
#if bge.logic.KX_SENSOR_JUST_ACTIVATED == keyboard.events[bge.events.SPACEKEY]
# and touchingGround === True:
# player.applyForce((0,0,400), True)
main()
So I have a player that can jump, but I want a player that can only jump when touching the ground.
Thanks for any help, also keep in mind I am very new to Python so please elaborate little with your response! Thank you.
EDIT: SOLVED