Download

FPS Tutorial fire projectile math

Hi,

I am following the C++ FPS tutorial on the wiki (which is great btw) and there’s a part that I don’t quite get yet. A little bit more explanation would be greatly appreciated. Here it is :



// Inside AFPSCharacter::OnFire()

FVector  CameraLoc;
FRotator CameraRot;
GetActorEyesViewPoint(CameraLoc, CameraRot);
 
// MuzzleOffset is in camera space, so transform it to world space before offsetting from the camera to find the final muzzle position
FVector const MuzzleLocation = CameraLoc + FTransform(CameraRot).TransformVector(MuzzleOffset);


I am not sure how the MuzzleOffset world space transform works.

So if I understand correctly (and correct me if I’m wrong) GetActorEyesViewPoint return the location and rotation of the camera in world space. Then we use the camera rotation get the MuzzleOffset in world space, but how is this working? What about the camera location? Shouldn’t we do something like :



FVector const MuzzleLocation = CameraLoc + FTransform(CameraRot, CameraLoc).TransformVector(MuzzleOffset);


Thanks

All it is basically doing is transforming MuzzleOffset from local space of the camera to world space. Personally I would think:

FTransform(CameraRot, CameraLoc).TransformPosition(MuzzleOffset);

Would be clearer!

Yes I think that it would be clearer as well, I was wondering why the CameraLoc was not use to create the FTransform. I’ve tried it and it didn’t seem to change anything from what I saw, but I am not sure why?

Thanks for your help