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.
28 Replies
look at how TFIT does it for the purposes of the overlay
I do a raycast with a fixed distance from the eyes
I don't really need to do a raycast or trace, I'm not trying to target anything
I think the math function that goes into it is the same
The float scalar is the distance in front of the player
sorry, missed a piece
And that multiplier is the distance? So 500 for 500cm?
yup
Neat 📸
Works perfectly ❤️
@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?
Hmm, now to figure out how to make sure that the spot isn't underground
The only way I know of to do this is to trace, and cast hit actor to landscape proxy
quite possibly, not sure what the best home for it would be. and it always ends up changing depending on the use case
yeah, but maybe just for UE specific stuff that gets asked occasionally and would probably never change
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?
good point. but a docs page should point out that AO exists, and there may still be merit in a "greatest hits" of it
For hitting the landscape I think its actually LandscapeStreamingProxy, the cliffs are FGCliffActor, but some rocks might be StaticMeshActor or InstancedFoliageActor
Solution
Do something like this, trace around and see what you get a hit on
That's what I ended up doing
why the Visibility channel? I only have guesses about the purpose of most of the channels but I haven't seen that one before
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...
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.
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 insteadThanks, 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.
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
any suggestions for coping with and/or detecting that it's behind?
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
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
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