So I have my Pawn movement set up, and I am able to fire projectiles. Part of my movement includes pressing “A” and “D” keys in order to rotate (roll) the pawn 90 degrees to the left or right. Each side of the Pawn has a different symbol I want to correspond with a different type of projectile, so press “A” or “D” to cycle left or right through firing modes.
I need to figure out how I can tell what the pawn’s rotation is (so what symbol is “active”), and use that info to fire the correct type of projectile. Basically I wand to have one button for firing, but the type of projectile fired varies based on the Pawn’s current rotation (roll) to the left or right.
This might not be the most elegant solution since I’m not extremely familiar with the blueprints yet, but I think you can add a node for Get Actor Rotation, the return value from that should let you break the rotation into pitch, yaw, and roll. You could use some comparisons to see if you’re rolled 0, 90, 180, 270 for four different firing modes.
Ok, so both implementations sound like they could work. I’m a bit of a beginner when it comes to blueprint, and coding in general though so please bear with me. For the second option, after I create the new variable and change its type to integer, how should I go about setting it?
This is what my rotation looks like at the moment…
Well you could get the Actor’s rotation using ‘Get Actor rotation’. And use that to identify the firing mode. I am guessing that your game is a top-down one (or atleast isometric). In that case you could break the rotation and use the Yaw component to determine the firing mode. (ie Yaw between 0 to 90 FirinMode1, Yaw between 90 to 180 FiringMode2 and so on).
Another option would be to use an integer variable called ActiveFiringMode. Simply cycle through it within your Event graph for Rotate Right and Rotate Left. ie You already have the event graph rotating the character on key-presses; you simply change the value fo this variable too along with it. For instance lets assume that ActiveFiringMode can take one of (0,1,2,3) as its values. When character is at 0 degrees, you have firing mode = 0. So in the event graph for rotating clockwise you do
ActiveFiringMode = (ActiveFiringMode+1)%4
in rotate anti-clockwise
ActiveFiringMode = (4+ActiveFiringMode-1)%4
Then within the event graph for Fire, you swicth between firing modes based on the value of ActiveFiringMode.
PS: ‘%’ is the modulus operator
To Get or Set any created variables, simply drag-drop it from left panel into the blueprint editor area. You will be shown two options ‘Get’ and ‘Set’. Chose accordingly.
Get will give you the current value of this variable, while Set will let you set a new value to this variable.
I could show you the screenshot of the full bluepeint at the end of the day (I’m at work now).
Ok, yeah I’m somewhat familiar with getting/setting variables in general. An example would be much appreciated though, so as to see better how to use those integer nodes you mentioned. Thanks
Here you go!
I am only showing the relevent portion of the event graph. The top portion handles Clockwise rotation and bottom part handles counter-clockwise rotation.
Actually the calculation at bottom can be simplified to:
ActiveFiringMode = (ActiveFiringMode+3)%4
But it makes more sense to me in the current state. But feel free to simplify.
Awesome! Just tested it out with a print string and this is exactly what I wanted. Wish I could have figured it out on my own, but seeing how this works gives me a better understanding. Thanks again.