Download

Change keys using blueprints

Hi everyone, I’m working on a top down shooter and I need help with a blueprint. I have, on the map, some trigger boxes that rotate the camera by X degrees around the character, where X is a value that I choose independently for each box. The problem is that the movement keys do not change with the camera, so the move up and move right keys become swapped (A and D to move forward and backward, W and S to move right and left), because the point of view of the camera changes. Hope that I explained it clearly.
I think there are two ways to act: the first one could be to rotate the capsule component of the character, according to the camera rotation. In this way the forward axis would change, but I don’t even know if it is possible to do this using blueprints.
The second way could be to simply change the movement keys: something like: “when you walk through the box, the new keys to move up are A and D, and the new keys to move right are W and S”. Note that it can’t be a simple swap, because, for example, for a certain box i could need to have S for forward and W for backward. I’ve tried a lot of attempts but nothing seems to work…

You could probably use the camera’s forward/right vectors, or a dummy component that you also attach to the swingarm (assuming you’re using one) and get the forward vector of that as it rotates around the player?

Uhm… I can’t imagine how does it works, can you tell me an example please?

Yup as Variss said.
I also have top down game, but my camera can be freely rotated.
For “translating” keyboard axis to in game directions i do this:

  • i created AXIS “event_move_right” (in project setings > input) which has A & D keys A = -1 D = +1 (because D moves right)

  • second event is “Event_move_forward” with W & S keys W is +1

  • now on event tick i read values of “event move right” and “event move forward”.
    I do not use events here i just read axis values for them. If you write whole name of your axis event you will see event and pure function that just returns value, use function.
    So i read both “move forward” and “move right” axis values then i do some vector math:
    First you need to “normalize” camera direction, so i get its “forward vector” multiply it by [1,1,0] and normalize same with “right vector” * [1,1,0] and normalize
    Then I multiply “move_forward” by “Forward vector” of camera, and “move_right” by “right vector” of camera
    Then i add both vectors and this gives me move vector that is pointing according to camera. This works great with character setup, or AI driven bots.

Ps.
I can make picture of this graph when i am back home.
I made function that gets as input: move_right, move_forward and actor reference (for forward and right vectors), then gives direction vector.

However there is problem of diagonal move. Which is SQR(2) = 1.414 factor (from adding vectors) instead of 1. I could not find any elegant solution to this yet, so i am not sharing my convulted math for it.

Couldn’t you just normalise the vector again after adding them, to get a diagonal vector of length 1?

I gave it a try! Thank you a lot!
Were you talking about something like this?

It works, but the caracter’s forward movements are slower than the right ones, just like the input axis move up value is lower than 1. I also tried to normalize the movemente vector as Variss says but does not solve the problem, so I don’t think it is caused by the diagonal move issue you were talking about.

Couple issues that could be coming up here:

Multiplying by [1,1,0] isn’t actually normalising the vector, it’s just negating the Z axis so that there’s no up/down movement, normalising is another step. As it turns out, the way you have it is fine though, because the forward/right vectors are already normalised.

This is a guess, but I think the reason that your forward movement is slower is because you camera is likely angled down towards the player at some angle, so the forward vector is actually pointing down a bit towards the player. When you zero out the z axis and just take the x/y components, you’ll be getting a smaller value than what the right vector is giving you (assuming the camera is not rolled in any way). If that’s the case, then what you can try is adding a scene component (just some dummy component), and attaching it to your swingarm (if that’s what you’re using). You may have to rotate it so that it’s “flat” (local Z pointing straight up). Then if you use the forward/right vectors of that component rather than your camera you should get even movement.

Oh you’re right, sorry I was a little bit tired yesterday evening ahah
By the way, my camera is actually rotated by 45 degrees on y axis, and in fact I thought that this could be the problem. I tried to rotate the forward vector (before multiply it by 1 1 0), and then also multiplying it by 1 1 1 instead of 1 1 0 but nothing changed.
So I’ll try the dummy component as you (and varis too) said

Not events, use functions there. I wrote how to get functions not events for axis values. So get functions instead of “input axis move up” and “input axis move right”.

And about normalizing:
when camera is at angle and you cut off Z value, that vector will be no more normalized (it will get shorter than 1). That is reason you need to stretch it back to size of 1. ie normalize. So after you multiply by [1,1,0] add normalize.

So… like this? (It works correctly!)

2ADeYsM.png