I’ve been developing a 2D game and I need my player to shoot vertically/diagonally.
When player is looking up, the weapon’s location will be switched to different socket and now when shoot is pressed, it should shoot vertically.
Or when player is holding “Look up” and “Look left / look right” button and shooting, the player should be able to shoot diagonally. I’ve thought to approach this problem with booleans, but it seems to get really complicated with booleans when I have multiple similar actions (there will be alot boolean type variables).
Do you have any suggestions? Any patterns perhaps?
Yes, as long as you keep track of the directional keys’ down states it should be perfectly fine to query their combined states at any given time (in effect what I did in the function UpdateMovementDirection()).
As for the bullet direction, yes, if you also implement the direction vector part then you can easily use that for setting the bullet’s velocity - just be careful to normalise the vector first (I had a specific movement working off this where I did not want the direction vector to be normalised). E.g. FVector(1.0f, 1.0f, 0.0f) is not normalised, so if you want to consistently set the bullet velocity you’ll need to do something like:
I tried to create something similar without the code being in a different class (thanks for “over-formalising” it!!). It seems the easiest approach. So when I’d call shoot function I just setup a switch there and based on the movementdirection also set the bullet’s velocity?
About the sockets tho… Right now I’m switching between socket locations whenever I look up with my character. But as “looking up” is axis based input event, it fires all the time and constantly sets location to either one of those socket locations. But as I see it now, there should be “look-up” animation separately and the sockets could be just bound to those animations so I shouldn’t switch between socket locations repeatedly. But when animation state changes, also the weapon location changes.
Hello again!
I’m sorry I didn’t ask you about this earlier, but I wanted to ask you if you permit me to use this code snippet in my thesis (I have modified it a little bit). I don’t want to run into problems where I feel I’ve used something that’s based on someone else’s creation. It would be a big deal for me