2
$\begingroup$

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: Screenshot

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.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)!

$\endgroup$
  • $\begingroup$ I still working on this script, all the directions are working (Up, Down, Left, Right,Diagonals...), the Run fonction work too. i just have to finish the header, add the Character Jump function, the jump hight, and make the Keyboard key editable in-game (easyly). All is customisable. All the instructions will be include inside the script (In French and English). I will post it here as Answer when it working correctly, but i think many improvements can be done. $\endgroup$ – Hack0re Sep 17 '15 at 11:51
  • $\begingroup$ I finished the script (the only function that doesnt work is to set in-game the jump hight). Here the functions of it: All the parameters are customisable in-game, the keyboard inputs, the movement speed (Walking and runing), the number of jump, the diagonals are working perfectly. The script is smart, and if you dont add the property, it will automatically use default values. I will add many improvements thereafter. $\endgroup$ – Hack0re Sep 17 '15 at 20:46
0
$\begingroup$

[FR-EN] Advanced Moving Script for the BGE V2.0 by Hack0re.

Warning, this script only work with Character Physics Type.

It does not work with Dynamic Physics Type.

The script include 95% of the instructions, in French and in English (142 Lines Header).

I will add more improvements in the near future...

Its my first real script, i just started in python, please be indulgent.

Features:

-Perfect for a FPS game.

-5 minutes needed to set in place (and even then).

-Moving in all directions, Diagonals and Running working perfectly.

-No pass through Walls or Sliding on ground.

-Walk speed and Running speed can be easyly edited in-game (Properties).

-Jump function with number of jumps can be changed in real time (You just unlocked the double jump).

/The jump hight not working for in-game, im sorry (if someone know how to do...).

-If the properties are not added, the script automatically use the default values.

-All the keyboard inputs can be "easyly" changed in-game , for making all the players happy .

-All the necessary instructions are include in the script (in French and English).

Downloads:

V2 (17/09/2015): https://mega.nz/#!m1cRlDIC!wrD1ovEznhxLGssZY26sndRUFv9amtsu_wVg_8VZ60Y

Please dont remove the Top Header.

Original link: http://blenderartists.org/forum/showthread.php?381505-FR-EN-Advanced-Moving-Script-for-the-BGE-V2-0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.