Why is my projectile not shooting straight near my character?

Hey AnXgotta

I’m not the one who asked the question in the first place so no, it’s not me who accepted the other answer (I think only the owner of the topic can do that anyway).

I’d like to try every option and yes I’m still (in very) need of your help please :slight_smile:

Ok so what you can try is a Single Line Trace for Object and get break the hit result like you do. This node will return the first object you hit, if any… be sure to Ignore Self. If you hit an object, get its location from the HitResult and use the formula I posted above to get the Velocity vector for your projectile. You only use the GunOffset for the spawn location of the projectile (and the formula above) to have the projectile fire toward where you were aiming. If you get no HitResult from the Line Trace you just use the location of your max distance for the trace hit… Camera world location + Camera.Forward * MaxDistance instead of the Hit Actor world location.

I really sucks at this…at least I have my stubbornness for me

Ok this is what I have right now !

I think Part 1 is ok (in red), I know you told me to use Single Line Trace for Object but I don’t know how I should handle the “Object type” requested by the node however using the Trace for Channel and using the Draw Debug I can see than I’m casting a collision trace where it should be (hitting the crosshair and the first object encountered). So at least I know I get the right value here.

Part 2 is me trying to apply your formula :
(LineTraceHitPosition - ProjectileSpawnPosition).Normalized * ProjectileInitialSpeed (which is 3000 here).
Let me know if it’s ok.

Part 3 is where I mess up for sure…I have to admit, I’m not sure what does
this mean : “Velocity vector for your projectile” so I’m improvising and no surprise it doesn’t work.

Sorry to force you to hold my hand and thank you for your infinite patience !

Alright man, here it is using a modified First Person Blueprint Example

First, I added a Scene Component called “ProjectilSpawnPoint” to the player blueprint to help with finding the vectors and getting the world position to spawn the projectile. I put this Scene Component as a child of the “Mesh” Skeletal Mesh Component so that it would follow the rotation of the player.

Next, is the blueprint. I use the Camera Component, Projectile Spawn Component, and a few other variables to do this. The MaxRange variable is an integer variable I have set to 3000… you can make it whatever you want the max range to be. I also made a variable called MaxRangeHitPoint as a Vector that gets assigned as the world position of the point of the max range of the weapon. Look at the blueprint for the rest and let me know if you need any more help.

1 Like

Wow…it’s clear, it works and I understand it !
You’re a very good and patient teacher.

/bow
/thanks

No problem, I’m glad it helped =)

This was extremely helpful. Just wanted to let you know, AnXgotta, you rock! :smiley: you helped me more than once already.

Hello! my bullet spawns at the spawn location, but isnt moving anywhere. i can walk into it and it damages me. :smiley:

Came up with a better version of your BP. In both “Vector - Vector” connect the “Impact Point” node from “Break Hit Result” and the projectile will always hit a specific object instead of the variable distance you set . Hope this helps anyone else . Cheers!

I know this is a super old thread but I have a similar issue where I can toggle from FPS and TPS and my crosshair is not in same place so I need to do something similar to position crosshair and shoot to the crosshair so it hits same point no matter which view you are in. Would you be able to help AnXgotta?

Hey kayrk. If you are using the same camera and simply moving it on perspective change, then yes this code will work fine. If you have two cameras, be sure to use the currently active one to get the values for the position and rotation.

I got it all working. Appreciate it.

Well I thought I had got it solved but ran into a issue. I posted about it over hereanswers.unrealengine.com/questions/698683/first-person-third-person-aiming-discrepancy.html if you have any insight AnxGotta

It might sound stupid but I’m not quite sure how you would get the gun offset for the variable you made (I assume its a variable) Do you find the vector between the pawn and the end of the gun perhaps?