2D Platformer Basic Shooting

Assuming the direction the player is facing is also the “forward” direction of the actor (it usually is), you can get the forward vector of the player’s actor (search “get forward vector” in blueprint) and then multiply that by whatever speed you want the bullet to go to get a velocity vector.

If you want the bullet to just go in the same direction with the same speed, I think this is the right way to do it. Your bullet will need to be an actor with some type of movement component (I think there’s a projectile movement component, but I haven’t really looked into it). Realistically, any movement component will do.

Movement components have a velocity that you can set (search “set velocity”). Set that to the velocity we calculated in the previous step and you should be good! You’ll want to make sure you’ve disabled gravity and any type of resistances in the movement component of your actor.

Hi, the way I would do it is like this:

1.- Create a blueprint with a projectile component, let’s call it ProjectileBP.
2.- Create an enum and set it with Left, and Right, let’s call it Direction.
3.- Create Inside ProjectileBP a Direction variable (that’s going to be an enum, with Left and Right options to choose), and set this variable as Public, and Expose on spawn.
4.- In ProjectileBP construction’s script put a switch with Direction variable, and set Velocity’s vector variable from projectile component: X=1.0,Y=0.0,Z=0.0 if Right, X=-1.0,Y=0.0,Z=0.0 if left.
5.- Finally in your character Blueprint (the one that fires the projectile) when you spawn the bullet, you will be able to select the direction you want it to go :).

Hope it helps!

I’m trying to spawn a bullet that goes the direction the player is facing at a constant speed. I can’t seem to figure out anyway of doing this (I’m pretty new.) Anyone know how to do this?

I don’t get the last step, how do I select the direction?

When you “expose on spawn” a variable, you have access to it before you create the actor on the world, so you are telling the projectile to set its velocity when you spawn it.
With the steps I gave you, you should get something like this when you try to spawn your projectile (ignore the player position):

So you create a Direction variable now Inside your character, that updates when you flip your character, or move to the other side, etc. Mine in this example is called ActualDirection and changes everytime I move to one side, or another.

You need to add ProjectileComponent to your class, and the you must check:

-Inital Speed must be greater than 0.
-Maximum Speed must be greater than 0.
-AutoActivate must be enabled.

My friend I think you need to learn a little bit more hahaha.

Here’s a really good tutorial.

It spawns the bullets right now, but they don’t move. How do I use the enum to make the bullets move, and in the right way?

The bullets will only fire right, and they collide with only the character. How do I fix this?

Thanks, those videos helped out. Sorry I’m really new to Unreal Engine.