Movement in different directions

Hi blender-heads, quick question,
How can I have my player move (using wasd) forwards, backwards, left, right and diagonally at the same speed?

For example:
if I hold W I should go 5y
if I hold A I should go -5x
but if I hold W and A, I seem to go much faster than just W or just A.

I’d like to go the same speed in all directions. I am using Servo Motion.

This is a bit hard to explain so i have provided a .blend file with instructions.
example.blend (381 KB)

If anyone could help I’d really appreciate it, thanks. :slight_smile:
Ross

That is normal as you add two velocities. See diagonal distance of a right angle grid is sqrt(2)=1.4…
If you want it differently you need to avoid the combination of velocities. Better treat it as different event.

E.g.

Forward only = (0,1,0)
Forward + Left = (-0.7,0.7,0)
Left only = (-1,0,0)

Just make sure not to activate “left” only by accident if it is a “forward + left” event.

I hope it helps

You would probably do well with a vector for your movements.



mv = mathutils.Vector()

# If you press right
mv.x = 5
# If you press Up
mv.y = 5

mv.magnitude = 5 if mv.magnitude > 5 else mv.magnitude # Cap the magnitude of the vector to 5


Thank you Monster, I understand, but I am not sure how to apply this. I am trying to avoid Python unless it’s absolutely necessary. So using Logic Bricks (using 1 state only), how can I achieve this? I’m tied down to one state for other reasons.

Is there a way to prioritise Logic Bricks? So when w and a is activated it makes w or a actuator stop?

Or is this a Python only answer? My aim was to create a game using no Python, but before I even get movement down, I’m stuck!

Thanks SolarLune, I will keep this in mind if I can’t get this working with Logic Bricks. :wink:

it is indeed a little bit difficult if you want to use the same keys as for straight movement.

To solve that there are several options.
On of them can you see at the attached demo file.
It uses a state change when an additional motion key is pressed or released.

The connections might look a bit confusing. This is as it replicates the same principles 4 times (one for each direction).
To get a better structure I separated state changing logic from motion logic.

So you get:
states 1 + 16 for straight motion
states 2 +17 for diagonal motion

The file contains another cube with the usual simple motion so you can compare :wink:

I hope it helps

Attachments

Movement.diagonal.blend (80.3 KB)

Wow, thanks Monster, really appreciate it. Never thought it would be that much hassle to get done! I am stuck to one state in my project so I don’t believe I can use that exactly, but I will try and work around it.

Do you advise I use (SolarLune’s) Python, considering I am bound to one state?
Will it be neater / easier in the long run?
Or should I rework all movement using many states?

My problem with your solution is if I use it, I have to re-make all the logic for every state.

So, what do you advise? :slight_smile:

I really do appreciate all of these replies from you guys, by the way!

In general i advice to separate user input from any other logic. I mean keep it in a separate state. You can have it enabled initally together with your current states (see demo file states 1+16).
The benefit is, you can display this logic without the other logic, which usually makes it easier to read. And you still have the option to see all at once ( shift + select state).

To keep the logic small You can use Solarlunes solution. Unfortunately you will need to implement motion in python. The advantage is you can have any direction like south-south-west.