Motion Question

I’m trying to create my protagonist’s motion system like in devil may cry, GoW and other action games like these.
I mean, if i press left arrow key the character will rotate to the left and then run in that direction, if i press up arrow key the character will go “inside the screen”, and so on… (so is different form the typical fps movement system, or the system shown in blendercoockies GE tutorial)

The base problem is that the keyboard gives digital signals, and so is impossible to emulate the movement like they are controlled by a joypad.

So i tried to control the player in only the main 8 directions:

Seen from above (there isn't movement along Z axes):

   (Y global axes in blender)
   \    |    /
    \   |   /
left    |    right (X global axes)
    /   |   \
   /    |    \

But my script seams not to work…
If any arrow is pressed the character will star walking haed.
If the up arrow key is pressed, then the orientation of the character should align to the globa Y axes, if the right arrow key is pressed then the character should align his orientation with the x axes, and so on…

My script is a total mess and it doesn’t work at all, so i ask you help…
Is this the right way to do this, and is there a python command for doing that and not work with rotation matrices?

Try using empties (E) around your player § and trackTo actuators to face them.
You may need to use vertex parent to keep them in the right spot. That’s what I do.

  E     E     E
   \    |    /
    \   |   /
left    |    right 
E ------P--------E
    /   |   \
   /    |    \
  E     E     E

Perfect, i’ll try!!!
I thought i could get it in this way, but i was thinking it was just a work around and not a real solution

Ok, i tried!
I managed the player to track to the empties parented to a “main” empty with the same location of the player.
But i wonder if it possible to use the copy location and copy rotation constraints in the game engine… They seams not to work… How can i copy the location of the player to the “main” empty without coping the rotation? And how can i copy the rotation of another object without coping the location?
If you can post me a blend you would help me a lot!!!

(i’m using 2.5)

In python you would use “.worldPosition” for location and “.worldOrientation” for rotation.
this site is great for python references

I’ll try to post a blend later today maybe.

import GameLogic

cont = GameLogic.getCurrentController()

own = cont.owner

def copypos (oggetto):
    scene = GameLogic.getCurrentScene()
    objList = scene.objects
    ogg = objList[oggetto]
    #set the owner location equal to the location of the object givet to the function
    own.worldPosition = ogg.worldPosition
def copyrot (oggetto):
    scene = GameLogic.getCurrentScene()
    objList = scene.objects
    ogg = objList[oggetto]
    #set the orientation of the owner equal to that of the object given to the function (not right)
    own.worldOrientation = ogg.worldOrientation

oggettoA = "box"

oggettoB = "orientazione"



oggettoA is the box controlling the player, oggettoB is an empty parented to the box and traking to the camera.
I want to copy the rotation around the z axes of the empty to the owner of the script.
Once done this, my motion script is finished!! :smiley: (do you think it would be useful to someone? Should I post it in resource with a blend file once finished?)

(good site alaseridan! A search function would be welcomed :yes: )

own.worldOrientation[2] = ogg.worldOrientation[2]

That brings up the Z axis, 0,2,3 = x,y,z. So in the future if you wanted to add a value to a coordinate that’s how you’d define which one.

I have attached the blend that shows the way I take care of movement.

You’ll notice if you grab the cube (the physics box) the empties will move with it.
But if you try to rotate it they don’t rotate with it. That’s because I have the center one “vertex parented.”

If you were to do it fresh from my blend (it’s already done) you’d select the cube and add a vertex where the center empty is.
Then exit edit mode and select the empty then the cube, go back into edit mode, select the vertex and press ctrl-p to vertex parent.

The arrow keys move you around. :smiley:

I did this in 2.49 but I also ran it in 2.53. Any Q’s just ask.


8way_movement.blend (141 KB)

I actually posted how to do this in the resources section not too long ago. I just used the eight empties around the player, and one to parent the camera to. Pretty well exactly like what was just posted.

In my project the one in the middle is also turned by mouse movement so that the controls are relative to where the camera is facing.

Heh, your’s does the same thing! Really the only difference is I use python.

Mine does that too, or did I misunderstand what you said?