How can I have a bullet travel a constant distance in the direction of the cursor?
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:
I have also set an editable, exposed in spawn variable in my bullet blueprint:
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?
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:
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.
answered Jul 31 '14 at 05:21 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here