Im making a script for replace all my logic bricks used for moving, runing and jumping.
I using "Character" Physics type for my player, and i using "Character motion" motion type:
Here is my script, i encounter some problems for making the motion correctly:
import bge
from bge import logic, events
def mouvements():
cont = bge.logic.getCurrentController()
own = cont.owner
keyboard = cont.sensors["Keyboard"]
VitesseMarche = 0.2 #Walking speed
VitesseCourrir = 0.5 #Runing speed
for key,status in keyboard.events:
if status == logic.KX_INPUT_ACTIVE:
# Avancer
if key == events.UPARROWKEY:
#Go forward
print("Avancer")
# Reculer
if key == events.DOWNARROWKEY:
#Go backward
print("Reculer")
# Gauche
if key == events.LEFTARROWKEY:
#Go left
print("Gauche")
# Droite
if key == events.RIGHTARROWKEY:
#Go right
print("Droite")
if status == logic.KX_INPUT_JUST_ACTIVATED:
# Sauter
if key == events.RIGHTCTRLKEY:
#Jump
print("Sauter")
mouvements()
The script need also Run and Diagonals functions (and mid-air moving if possible).
I have already tested some things, but there is always a problem.
-Or the movement still continue after the key no longer pressed.
-Or the moving are not local.
-Or the diagonals not working...
I have tried this:
own.orientation*Vector((0, 0.2, 0))
Found at: How to use KX_CharacterWrapper.walkDirectionHow to use KX_CharacterWrapper.walkDirection. But i may be bad.
This script must be the lighter as possible.
I have a last thing, it is possible to make the inputs (UPARROW, DOWNARROW, LEFTARROW...) changeable, easyly, and in-game?
Thank you and have a nice day (I will include the name of the guy who help me in the credits of the script)!