I have a character who plays his walk animation when he walks, but what if he is behind a wall? He would look sort of goofy walking when hes in place. Is there a way I can have a property ("Moving") be toggled to 1 when hes changing his position (not rotation) in 3d space? Any helps is appreciated; I would like to have this in logic bricks if it is simple. Thanks!

  • 1
    Seriously? Stop using integers and use Booleans for true or false situations. You can simply have it detect True or False, instead of 1 or 0. toggle then works on Booleans. – X-27 Mar 17 '15 at 0:56
up vote 2 down vote accepted

You already answered your question by your own:

Behavior: When moving play walk animation

This implies: When not walking -> do not play walk animation.

As you do not explicitly told the character to stop (e.g. by command) you need to detect any events that stop it from moving.

There are many options to detect such events:

  • no movement requests from user
  • getting other requests from user (e.g. jump, run, stand, crouch)
  • hitting a wall
  • floating (e.g. when falling, jumping)
  • speed below a limit

I guess you want to know the last option. This is not possible with logic bricks. You need Python to activate actuators when the object does not move anymore:

import bge
controller = bge.logic.getCurrentController()
owner = controller.owner

limit = owner.get("limit", 0.001)

lastPosition = owner.get("_lastPosition")
position = owner.worldPosition.copy()
owner["_lastPosition"] = position

if lastPosition is not None:
    travelledDistance = (lastPosition-position).length
    if travelledDistance <= limit:
        for actuator in controller.actuators:
            controller.activate(actuator)

This needs to be activated all the time (enable True Level Triggering).

Attention

  • this is inefficient and should be used at a very limited number of occurrences
  • this does not differentiate between other situations when the character is not moving (e.g. sitting, sleeping)
  • you can tweak the limit by setting a float property limit
  • "this is inefficient and should be used at a very limited number of occurrences" - I will use this a lot and I need it to be able to reply quick many times; is there a way to fix that? – blackhole Mar 27 '15 at 0:19
  • A more efficient way is to use other detection methods, such as a collision sensor. Obviously this will only work on expected collisions (e.g. the character stops when the front part is colliding with a wall). – Monster Mar 31 '15 at 12:27

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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