1
$\begingroup$

More specifically I want the character to rotate a complete 180 when I press the left or right arrow key. But I don't want it to rotate again if I press the same key in sequence. Example: Character is facing Forward. I Press Left, the model rotates 180 left. I press Left again nothing happens because the model is already rotated (Would be perfect). Ive searched all over web but can't really figure this one out :/ Heres my script

import bge


def main():

    cont = bge.logic.getCurrentController()
    player  = cont.owner
    keyboard = bge.logic.keyboard

    if  bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.LEFTARROWKEY]:
        player.applyRotation((0,1.57,0), True)

Any help will be appreciated thank you!

$\endgroup$
0

1 Answer 1

1
$\begingroup$

It sounds like you want a specific (end-) pose rather than a turn. Therefore I suggest to split the operations: Set target pose (turned east or whatever) -> animate towards the target pose until it is reached (the object faces east ). Subsequent turn requests will set the same target pose without visible effect.

In your case you do not want to animate so you can skip the "animation" state:

import bge
import mathutils
from math import radians

keyboard = bge.logic.keyboard
if  bge.logic.KX_INPUT_JUST_ACTIVATED == keyboard.events[bge.events.LEFTARROWKEY]:
    controller = bge.logic.getCurrentController()
    player  = controller.owner
    keyboard = bge.logic.keyboard

    FACE_EAST = mathutils.Matrix.Rotation(radians(90.0), 3, 'Z')
    player.worldOrientation = FACE_EAST 
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .