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 can I have a bullet travel a constant distance in the direction of the cursor?

Hi everyone,

Maybe I'm not understanding well how projectiles work in UE4, but I have a problem with them. I'm making a simple 2D game in which the player can shoot in the direction the mouse marks.

EDIT: I'm working with the 2D platformer preset added in Unreal Engine 4.3, with paper2D plugin.

I've done a simple projectile (bullet) shot by the player towards the mouse which is working fine. Here is the blueprint for this:

alt text

I have also set an editable, exposed in spawn variable in my bullet blueprint:

alt text

Now, the problem is when I shoot with my character, the bullet will travel to where the mouse is. If the mouse is near the player, it will stay there until it expires. What I want is the bullet to travel a constant distance in the direction the mouse is. If the mouse is near the player, I want the bullet to go past it.

I thought that by having a unitarian direction vector (bottom part of first blueprint) and multiplying it by some number (distance I want it to go) and setting this as the velocity, it would work. Obviously I'm wrong.

What am I missing?

Thank you.

Product Version: Not Selected
Tags:
blueprint.png (145.0 kB)
more ▼

asked Jul 31 '14 at 11:30 AM in Blueprint Scripting

avatar image

Pryrios
93 4 10 18

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

1 answer: sort voted first

Before you calculate the direction and rotation vectors for your bullet, try changing the Y coordinate of the mouse position you get to the Y coordinate of the character position:

newbp

Based on your previous comment that the world direction of a mouse click is "x=0, y = -1, z = 0" it seems like you would want your projectile to move only along the X Z plane.

newbptemp.png (157.4 kB)
more ▼

answered Jul 31 '14 at 05:21 PM

avatar image

stuartc
86 2 1 2

avatar image Pryrios Jul 31 '14 at 05:36 PM

I cannot thank you enough for this. I've been looking into it and didn't think about this tiny detail.

It's logic as the Y coordinate of the mouse doesn't need to be the same as the character. The bullet was behaving correctly but was being shot in 3D instead of the plane it was intended to be.

Thank you again!

(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