8 directions

I need help finding a way to allow the player to move in all 8 directions without having tank-like controls. I have tried changing the direction of animations like this:

Walk forward

Walk Left

He still faces forward but moves to the left. How do I solve this?

Python or using Track to actuators set to face empties that are vertex parented to the Player object.

You could make a really easy vertex thing that wouldn’t require all the nodes.

Okay i familar with code, so would i be able to make something like this?



if keyboard_check(right)

I know its not exactly like the python language but is this type of code possible?

It sounds interesting, but would i be able to return the player to the idle pose while facing the same direction?


if “direction=90” while the players action is walking, would the players idle action be “direction=90” as well?

Ha, that’s GML (Game Maker Language)-like. That kind of code is possible, but it would be more complex in Python, obviously. An easy way I use is this:

  1. You move the object and assign the speeds to variables.

from bge import logic
from bge import events
import math

cont = logic.getCurrentController()
obj = cont.owner

x = 0
y = 0

keyboard = logic.keyboard.events

if keyboard[events.LEFTARROWKEY]:
     x = -obj['movespd']
elif keyboard[events.RIGHTARROWKEY]:
     x = obj['movespd']

# Same for Y-axis and Up and Down keys

obj['mx'] = x
obj['my'] = y

obj.setLinearVelocity([obj['mx'], obj['my'], obj.getLinearVelocity()[2] ]) # Move the object on the mx and my variables, moving according to gravity, as well

  1. You rotate the object (or the armature, if you have one) by the angle of the movement:

ori = obj.orientation.to_euler()
ori.z = math.atan2(obj['my'], obj['mx'])
obj.orientation = ori

That should work fine.

Haha you know it too eh? nice. Okay i see, and if i want to add this to the armature or mesh, i would make something like this in the game logic?

This was taken from a python movement example

Actually, the Move actuator is unnecessary in this example as you are using the object via the setLinearVelocity() function. Also, I would personally rotate the armature, not the object itself.

Okay i give in, can you please tell me where I plug in these codes? lol :confused:

Well, I think that it should work if you plug the script into a Python controller connected to an Always sensor. You’ll have to add the portion for the Y-axis checks (up and down arrow keys).

EDIT: Here’s a blend file example - my script above had some errors and inconsistencies.

BlueArrow.blend (454 KB)

Ohhh i see now, okay i give that a whirl, but for some reason when I to load your .blend file it says its incomplete? lol

edit: forget the incomplete part haha, the download stopped early :slight_smile:

Okay so it works! but erm, for some reason the character moves left when i press up and right when i press down. I made a box that surrounds the character (it was from watching a basic game engine tutorial on blender cookie). could that be an issue?

I don’t think so. I believe I’m just using different axes for movement than you. For example, in my file, +Y is forward. If +Y isn’t forward in your file, it won’t work the same.

Okay that was the problem, i just turned the axis to the side and now its working. However there is one more problem lol. My character isnt moving, im looking into it right now to understand why its not functioning properly.

Btw, where can I find a website that has a dictionary of all the python 2.7 functinos?

He isn’t moving?

Here’s a link to the Python 3.0 (for Blender 2.59) documentation.

Unfortunetly no :/. the scipt allows my character to turn but not move and im not sure why. For now i will use the game logicwhen it comes to movement. Thanks for the link, this will help out alot :slight_smile:

It should work… The object has to be Dynamic to move by linear velocity. Is your object Dynamic?

Oops i forgot about the dynamic switch, the object is not suppose to fly upward though. Why is it doing this?

Most likely because you’ve got something else inside of your character that is also physics enabled. The object goes careening off because another physics-enabled object is forcing a collision. Disable that physics-enabled object’s physics.

For example, for most set-ups with a character, I believe it should be:

Mesh (no collision) parented to Armature (no collision), parented to collision box (dynamic)

Only the collision box should be Dynamic and physics-enabled.

Ive tried what you have said, and I have found nothing. I even tried to get rid of the box and I still see the same results :confused: