Download

How to Line Trace from Camera Centre

I’m trying to trace a line from Camera Centre but line is being traced from Player’s eye location. I’m using the function “GetActorEyeViewPoint”. I’m doing this in my Rifle Class.
Here is the photo:


But I’m overriding this in Player Class later by Getting Camera Location to trace a line by overriding a pawn function called “GetPawnViewLocation” but still the line is being traced from Actors View point and not from Camera Centre.
Here is Photo of Player Class:

Note: While overriding the “PawnViewLocation” in Player class, I didn’t remove the “PlayerViewpointLocation” from Rifle Class. It is still there.

Assuming you’re using something vaguely resembling the default camera stuff that Epic gives us, you’re probably looking for either AActor::CalcCamera() or PlayerController::CalcCamera(), both of which take a float DeltaTime (ie input to Tick), and an FMinimalViewInfo& OutResult to return Location, Rotation, FOV, etc.

The documentation for “GetActorEyesViewPoint” says:

Returns the point of view of the actor. Note that this doesn’t mean the camera, but the ‘eyes’ of the actor. For example, for a Pawn, this would define the eye height location, and view rotation (which is different from the pawn rotation which has a zeroed pitch component). A camera first person view will typically use this view point. Most traces (weapon, AI) will be done from this view point.

So it’s not the camera position. It’s meant to return the position and direction of the view of the Actor for things like the PawnSensingComponent. You can override it to set the view point of those as well.

Just letting you know so you know what it’s for

1 Like

Thank You so much