Get location in front of player

How can I get the location just in front of the player? Ideally I'd want to make sure nothing occupies the space as well. From past experience I'm guessing it has something to do with getting the player camera and the forward vector, but I'm not sure exactly.
Solution:
Do something like this, trace around and see what you get a hit on
No description
Jump to solution
28 Replies
Robb
Robb3mo ago
look at how TFIT does it for the purposes of the overlay I do a raycast with a fixed distance from the eyes
SirDigby
SirDigbyOP3mo ago
I don't really need to do a raycast or trace, I'm not trying to target anything
Robb
Robb3mo ago
I think the math function that goes into it is the same
D4rk
D4rk3mo ago
The float scalar is the distance in front of the player
No description
D4rk
D4rk3mo ago
sorry, missed a piece
SirDigby
SirDigbyOP3mo ago
And that multiplier is the distance? So 500 for 500cm?
D4rk
D4rk3mo ago
yup
SirDigby
SirDigbyOP3mo ago
Neat 📸 Works perfectly ❤️
D4rk
D4rk3mo ago
@Robb (Mods don't work on 1.0) do you think its a good idea to add code snippets like this to the docs, like maybe one page with images and a brief description of what they do?
SirDigby
SirDigbyOP3mo ago
Hmm, now to figure out how to make sure that the spot isn't underground
D4rk
D4rk3mo ago
The only way I know of to do this is to trace, and cast hit actor to landscape proxy
Robb
Robb3mo ago
quite possibly, not sure what the best home for it would be. and it always ends up changing depending on the use case
D4rk
D4rk3mo ago
yeah, but maybe just for UE specific stuff that gets asked occasionally and would probably never change
SirDigby
SirDigbyOP3mo ago
That's what answer overflow will end up being, right? That doesn't seem to be working when I hit a cliff actor. Are there any other outliers?
Robb
Robb3mo ago
good point. but a docs page should point out that AO exists, and there may still be merit in a "greatest hits" of it
D4rk
D4rk3mo ago
For hitting the landscape I think its actually LandscapeStreamingProxy, the cliffs are FGCliffActor, but some rocks might be StaticMeshActor or InstancedFoliageActor
Solution
D4rk
D4rk3mo ago
Do something like this, trace around and see what you get a hit on
No description
SirDigby
SirDigbyOP3mo ago
That's what I ended up doing
Robb
Robb3mo ago
why the Visibility channel? I only have guesses about the purpose of most of the channels but I haven't seen that one before
D4rk
D4rk3mo ago
Unreal Engine
Collision Filtering in Unreal Engine 4
Choosing what collides is obviously very important, but it can be tricky, and it’s a problem that we have spent quite a while discussing while developing UE4. The system we have can seem a little complex at first, but it is very powerful and consistent, so I wanted to give a little background on how we arrived at it. We’ll talk about the differe...
D4rk
D4rk3mo ago
Its the default setting for trace and I didn't change it for the example, but you can get different results by tracing in different channels.
Archengius
Archengius3mo ago
that is not the correct way to trace from player camera it does not account for any camera modifiers or view mode specific modifications to the view you want APlayerController::GetPlayerViewPoint which does not seem to be BP exposed for some reason, so what you can do instead is Player Controller -> Player Camera Manager -> Get Camera Location/Rotation you can also hijack the fact that GetStreamingSourceLocationAndRotation just returns the same value as APlayerController::GetPlayerViewPoint and call that function instead
D4rk
D4rk3mo ago
Thanks, I have noticed that the trace is a little bit off sometimes, this seems to explain it. I'll update all my functions to use this method instead.
No description
Archengius
Archengius3mo ago
just keep in mind that this location is a few frames behind if you try to check it on the server for a remote client if you go through portals it can be behind A LOT actually resulted in some bugs in the base game
Robb
Robb3mo ago
any suggestions for coping with and/or detecting that it's behind?
Archengius
Archengius3mo ago
do not expect player camera position to ever be accurate or even representative of the client sided position do tracing and any related activities on the client only pass resulting actions to the server example: xeno zapper actually does camera tracing, overlap detection and VFX on the client the only thing that server gets is a list of actors that should get damaged and a location of the impact
Robb
Robb3mo ago
so a client side mod could make it possible to hit any loaded creature if it wanted to? not a balance problem for this game, just checking understanding
Archengius
Archengius3mo ago
yes I generally also follow the assumption that the client cannot be trusted, so xeno basher also does server sided timing and validation so it will refuse to hit anything more frequently than you can swing it, with a small window to compensate for ping
Want results from more Discord servers?
Add your server