x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.alt text

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.

Product Version: UE 4.21
Tags:
capture.png (250.1 kB)
capture2.png (250.1 kB)
more ▼

asked Feb 17 '19 at 11:39 PM in Using UE4

avatar image

Dino dragon 900
10 1 1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

alt text alt text

capture.png (126.7 kB)
capture1.png (191.2 kB)
more ▼

answered Feb 18 '19 at 12:39 AM

avatar image

ThompsonN13
10.1k 33 10 25

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question