My One Deviation

At first I wanted to use a function with out variables because it’s the cool new thing on the block, but I found my code wasn’t very dry having to redeclare the out variables throughout my code.

Then, I wanted to add the LineTraceEnd and PlayerViewPointLocation variables to the Grabber private parameters and just have that edited whenever I needed it with a function call at each point, but I didn’t like that much either because there was a bit of black magic I was making happen, and it wasn’t exactly clear what the function was actually doing.

How would anyone know that after the GetPlayerLineTraceVectors function actually edited the PlayerVectorStart, and the PlayerVector end parameters and that they were supposed to use those two parameters after calling that function. This was on top of making the GetFirstPhysicsBodyInReach function unhappy because it lost it’s const status and was now editing part of the object.

That was going to be my answer though, but I decided that I didn’t like it and went with the lessons instaed with one difference. I didn’t like having to use this block of code twice:

FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;

GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(
	OUT PlayerViewPointLocation,
	OUT PlayerViewPointRotation
);

So I searched for an alternate solution. There was really only one piece of code that needed the PlayerViewPointLocation, so why not get that some other way? So that’s my one difference, I got the GameFramework/Actor.h header, and then got the actor location.

GetWorld()->LineTraceSingleByObjectType(
    OUT Hit,
    GetOwner()->GetActorLocation(),
    GetPlayerReach(),
    FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
    TraceParams
);

I also made sure that the actor location was the same as the player viewpoint location as I would imagine that would might be at the bottom of the player box, and the other would be near the top. Luckily, for now, we’re an orb, and this location is the same.

LogTemp: Warning: PlayerViewPointLocation: X=229.397 Y=811.728 Z=67.000, Actor Location: X=229.397 Y=811.728 Z=67.000

If there comes a time that this is different, I might just add an offset to the GetActorLocation bit of code that’s tied to the camera player offset somehow.

2 Likes

Wow great hob with your post! Very impressive work!

2 Likes

Privacy & Terms