1
$\begingroup$

so I have a character in bge and I want to play an animation of him falling when he falls. I've tried using a collision sensor and enabling invert, but whenever the character jumps, it plays that animation, instead of the jump animation. I also have an always sensor connected to the idle animation, and the game engine just plays that instead of the fall animation. Any help is appreciated! Thanks!

Edit: Is it possible to detect the velocity of the character and play the fall animation when greater than a certain value?

$\endgroup$
  • $\begingroup$ You could check its position on the z axis and compare it to a stored value that changes when he climbs or descends normally. If the position is less than the stored value, you play the animation. $\endgroup$ – Anthony Forwood Jul 3 '16 at 0:16
0
$\begingroup$

KX_GameObject.worldLinearVelocity

On a Physics object the Z-axis of the coordinates would be negative.

As static objects do to move (via Physics engine) this attribute will remain (0,0,0). This will be the case on physics types Static, Occluder, Sensor, Navigation Mesh, Character. This is a bit strange as this types (except Static) have not really much to do with physics (it is more a purpose type). Changes in location (which is basically a teleportation), can only be tracked by recording the previous position and comparing it to the current one.

Here is an example:

import bge

PROPERTY_LAST_POSITION = "last.position"

gameObject = bge.logic.getCurrentController().owner
currentPosition = gameObject.worldPosition
lastPosition = gameObject.get(PROPERTY_LAST_POSITION, currentPosition)
gameObject[PROPERTY_LAST_POSITION] = currentPosition.copy()
positionDifference = currentPosition - lastPosition

isFalling = (positionDifference.z < 0)

controller = bge.logic.getCurrentController()
for actuator in controller.actuators:
    if isFalling:
        controller.activate(actuator)
    else:
        controller.deactivate(actuator)
$\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.