How would I go about creating 2d projectiles?

I am working on a 2d RPG (It’s 2d because I thought it would be cool concept that is uncommon) and I want to implement projectile weapons into the game. The problem I am having is that I want to make the game compatible for Console players, and they don’t have a cursor that can move around freely like a mouse on PC. Is there any way I could make a projectile based weapon that shoots left or right or in the direction the character is facing? My thought would be that I would want to find the direction the player is facing, then tween the object but I don’t know if you can get the direction the player is facing. If anyone has any ideas to try or any methods that would work feel free to share, I appreciate any help or any replies! Also if anyone has any articles about the topic they can link, I would appreciate that to help me learn more!

1 Like

You can get direction playing is facing by using getting the HumanoidRootPart.CFrame.LookVector.

You can either get the Camera CFrame’s lookVector or Character Humanoid Root Part CFrame’s lookVector
I suggest using the Camera

workspace:GetPropertyChangedSignal("CurrentCamera"):Wait()
local Camera = workspace.CurrentCamera
local DirectionFacing = Camera.CFrame.LookVector

DirectionFacing will be a unit vector describing where the camera is pointing or looking at.
You can set the projectile velocity to ProjectionSpeed*DirectionFacing
That should do the trick!

In addition to using HumanoidRootPart.CFrame.LookVector, you can also use UserInputService to see where the right thumbstick is positioned, and aim at where that’s aiming. I’m assuming since you said it’s 2D that you mean either side scrolling or topdown view, and using the thumbstick to aim like a mouse would work in either of those.

2 Likes

Actually, this sounds like a really good idea! I didn’t think of this before, but that way it would most likely ensure that the projectile is going either left or right. I’ll definitely look at this right now and see what I can do.