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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

2D Platformer Basic Shooting

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?

Product Version: Not Selected
Tags:
more ▼

asked Feb 15 '15 at 01:45 AM in Blueprint Scripting

avatar image

Enrage
1 1 2 1

avatar image Membrilloski Feb 15 '15 at 02:04 AM

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!

avatar image Enrage Feb 15 '15 at 02:36 AM

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

avatar image Membrilloski Feb 15 '15 at 02:48 AM

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): alt text

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.

answer.png (67.6 kB)
avatar image Enrage Feb 15 '15 at 03:03 AM

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?

avatar image Membrilloski Feb 15 '15 at 03:07 AM

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.

avatar image Enrage Feb 15 '15 at 03:22 AM

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

avatar image Membrilloski Feb 15 '15 at 03:24 AM

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

Here's a really good tutorial. https://www.youtube.com/watch?v=IYbGEkMTT1U

avatar image Enrage Feb 15 '15 at 04:24 AM

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

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

1 answer: sort voted first

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.

more ▼

answered Feb 15 '15 at 01:55 AM

avatar image

Lojo
90 2 2 9

(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