Download

Firing at Offset (Not Centered) Crosshair (3rd Person)

Searched a bit, a lot of round-a-bout discussion but nothing direct to what I am looking for.

  • 3rd person game, zoom-in aim mode where crosshair appears.
  • Crosshair is not centered and located down from center a bit.
  • Using a camera > GetWorldRotation>GetForwardVector x distance setup to find the end point (for line trace)
  • Obvious issues are alignment breaks depending on how close you are, and end point is calculated based on camera look.

Goal: How do I get vector for the direction exactly behind my offset crosshair so both issues would be solved and I can freely move my crosshairs anywhere?

2021-08-29_14h13_47

Any ideas to help set me on the right path would be appreciated!

You can use Deproject Screen to World | Unreal Engine Documentation or Deproject | Unreal Engine Documentation, which gets the world space position of a 2D screen coordinate; it’s not a line trace, it gets the position on the actual plane of the screen. Also, for actors and components, you can get the forward vector directly (you don’t need to use the rotation).

How are you drawing the cursor?

Okay I hadn’t heard of those let me play around. Thank you for the suggestion.

1 Like

Blockquote

Right now it is a UMG widget

I went down your path and I got it working in a very very manual way.

I’m not the biggest fan as I have to manually input the offset into the blueprint whenever I change the reticle location vs. having it update automatically. (Picture a non fixed cursor that is shooting all around the screen).

Ngl it’s a little more work than it needs to be, but this works:

Using canvas slot position:

Using render transform translation:

You can use one or the other, they both give the same result:

Also, you want to make sure the position is at the center of your cursor. I did it by setting alignment to (0.5, 0.5):
image

This is really good stuff. Thank you. I haven’t tried it yet since I’m mobile but a quick question: is your image 66 part of a canvas widget? I’m assuming the whole widget isn’t a full 1920x1080 resolution, since it looks like in this scenario you are setting the position.

Here’s another method:

For both canvas slot position and render transform translation I’m having a hard time latching on to the image asset in the widget. Keep getting this error message:

Both the Reticle Center Dot and Reticle Canvas are set to variables and Dot is in Slot Canvas Panel:

I noticed you are just calling an image and not a widget?

Yeah, just an image on a canvas. It’s weird to use 1920x1080, but it works for all viewport sizes; though, it doesn’t hit the right & bottom borders unless the aspect ratio is the same.

Yeah, but I tested the same thing with a widget, too, and it worked (I kept the image at (0,0) in the widget); an image is a widget, also, so they both work the same, so you just need to get the widget itself, not anything inside it. Alignment is the pivot point of the widget, which is the origin of it, so setting it to (0.5, 0.5) moves the origin to the center of it.

As for which to use (canvas slot position or render transform translation), the canvas slot position sets the position of the widget directly, whereas the render transform translation offsets the widget from its location, so render transform translation only works if the widget is at (0,0).

This is what the widget looks like:

Also, I noticed you’re on UE5. I’m on 4.20, but that shouldn’t make a difference.

This is all super helpful, everything is just being blocked by this Reading none from Widget or Image in Widget call.

I know it works because we use it to render the widget on screen to show. I need to figure this out and the rest will fall in place.

I think the problem may be the “ReticleHUDSet” isn’t set to anything. Also, you should be using “GetOwningPlayer” there, but that’s small.


BUT, I just found a much better & simpler solution, lol:

It works perfectly and reaches the borders of any viewport size (which means it’s accurate). Make sure the center of the target is at (0,0) in the widget.

This is such gold. I have it working perfectly now. Thank you for working this with me.

I did notice you are pushing it to the player screen instead of the viewport.

1 Like

So, I’m just coming back to this after a few days and I don’t think it was working as I thought it was.

Video of issue:

Reticle Setup - as you can see from the vid it appears to be going to 0,0 on the 1920x1080 canvas. Same thing if the reticle image inside the canvas is at 0,0 OR in the center:

Since I am rendering the reticle on primary fire, (center down 30) I just set my widget variable here:

And calling into play here according to your example above:

While my cursor isn’t moving around on screen like yours, it is off center so there is something in that mix that isn’t working correctly. Thought I would try you one more time :slight_smile:

Edit #1 For the record for anyone looking at this post, the reason I want to use the reticle as the endpoint, rather than a hardcoded setup like this:

…is that it becomes extremely inaccurate the closer the hit is to the start point, as you can see here:

Edit #2 I feel like I’m realllly close with this setup:


(This is how I setup my last example) First, your reticle image isn’t located at (0,0) because it’s not in the top-left corner (where (0,0) is at). Second, you need to set the image’s alignment to (0.5,0.5) to make the center of the reticle the origin. This will make the position of the widget the center of the reticle.

Then in blueprint (though, you can also do this in the widget), you set the widget’s position directly using a variable & “Set Position In Viewport”. This makes “getting” the widget’s position easy because we already have it stored as a variable (i.e. we don’t need to get the widget’s position, just use the variable).
image
Same picture from my last post

The reason I chose this way is because the setting positions is perfectly accurate to the pixel.

Then, in your third picture, you need to push that point forward using the direction just like you did here:


But this won’t solve your main problem:

In that case, you need to first trace from the camera/reticle to the world, and wherever that point hits is where the character aims. Then, when you shoot, the gun trace goes from the character’s gun to that point. That way, the character always aims at what the reticle is on.


Obviously, you only want to aim at it if it’s in front of the character.

Got it! Yes! The game changer here was using the Deproject World Position as the starting point rather than the socket location on the gun.

However, I STILL don’t understand why the other way didn’t work though…logically its a straight line from the socket to the same deprojected reticle to world space end point.

Regardless, your setup allowed me to freely make reticles and just auto-place them with a few nodes in the blueprint so big efficiency gain there too. You’ve been a big help midgunner.

1 Like

No problem.

But I think there may still be an issue with making the starting point at the camera/reticle. For example, if the character’s weapon is blocked by something (like when hiding behind a wall), they will be able to shoot through it since the shot is coming from the camera rather than the weapon.

Actually yeah that’s a good call. It’s not a problem for projectiles because I’m just using that line trace to get the endpoint and then I go ahead and fire the projectile so the wall will still block it on its way to that endpoint. However for line trace instant weapons you’re right it would be skipping right over the actual traveling distance.

Perhaps I will revisit doing a line trace from the socket to the endpoint again.

1 Like

Yeah, that’s what I was going to suggest, so good to know that’s how you’re doing it.