How to make the player shoot a projectile?
Hi I'm making a game called Cube Run A game you are a cube moving from the start of the level to the end.
The player move left and right on the Y axis and moves constantly forwards in the X axis.
The movement method can be found down below.
I would like the projectile to come from the front of the Cube in the X axis and move ahead of the Cube for 3 before it disappeared or if it hit an object.
asked Feb 17 '19 at 11:39 PM in Using UE4
Dino dragon 900
for your situation it sounds like you want to spawn a projectile, then on hit do X (damage, destroy actor, etc), or if not hit then destroy itself. now you dont exactly mention how you want to handle the no hit situation. you say "move ahead of the Cube for 3" but that doesnt really tell us much, 3 what? seconds? units? meters? grid spaces? who knows. just a note for reference check out the first person template since they do almost exactly this.
anyways to start you need to create a projectile actor: right click components window, select blueprint, then select actor in the new window. next add a mesh that has collision and add a projectile movement component. you could also make your own movement method if you were so inclined. next select the movement component and set its initial and max speed (1000 or more should work for now). now go to the event graph and right click and search for event hit. drag off event hit and search for destroy actor. then connect the other actor pin from the event hit to the target on the destroy actor. this will result in the projectile destroying any actor it touches.
next we will need to create a method to spawn the projectile. to do this open your cube character or pawn (the thing that you control, which im going to call character from here out). in the character go to the event graph and right click and search for the input event that you want (any key will do). now drag off the input and search for spawn actor from class. set the class to that of your projectile. all thats left now is to set the spawn location and rotation. for location the simplest method will be to add a scene component to your character and place it where you want the projectile to spawn, this way it wont be overlapping your character when it spawns which would be bad (itd destroy your character). then get the scene components world location and plug that into the spawn actor node (you may need to split the transform struct pin on the spawn actor node). for rotation just get your actors rotation and plug that into the spawn node. and that should be all.
course youll need to clarify the move for 3 bit, but that can be done simply in the comments.
answered Feb 18 '19 at 12:39 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here