PlayerViewPoint should not be where you fire the gun from

The more I tried this out, the worse the idea got. Bullets ideally should come from the end of your gun barrel and not the player’s view port or the camera manager or anything of that sort. Here’s why: Look up and fire your gun. Your gun is pointed forward but your bullet went up, makes 0 sense logically. Unless your viewport is tied to your gun’s direction, this won’t work well because the gun will never hit what the gun is pointed at only what the player is looking at.

This is also a screenshot of what happened to me:

Because my camera wasn’t offset by the character and was standing directly behind the character, the bullets would have just hit the character mesh. So to fix this, I had to go to my Collision settings and change Bullet to Ignore on the Character Mesh. Now I’m not firing at myself but through myself.

It’s an odd way to fire bullets to be honest. This only really works if your gun and the middle of the screen are aligned.

I felt the same way, and actually did two line traces. First one is the same from the tutorial, and I saved it as the CameraTargetHitLocation. Then I created a USceneComponent in front of the barrel and performed a second trace from there to the CameraTargetHitLocation.

This drew the trace from barrel to wherever the user was aiming.

I had some collision issues with gun, so the projectile spawn point is out abit (like 10cm). Ideally I’d disable or ignore collision with the gun, but the quick fix was good enough.

EDIT: I just realized you’d have the same issue with this implementation. But that’s fixable with a second channel for the camera hitLocation that ignores the player.

1 Like

I thought the same due to implementing a toggle between third and first person cameras and implemented a solution mostly by changing two lines of code. Setting the location and rotation variables to the PawnViewLocation and ViewRotation respectively and commenting out the GetPlayerViewPoint gets the line trace drawn from the Pawn from almost exactly the same height as the gun but from the chest of the pawn character.

    FVector Location = OwnerPawn->GetPawnViewLocation();
	FRotator Rotation = OwnerPawn->GetViewRotation();
	//OwnerController->GetPlayerViewPoint(Location, Rotation);

As for collision I set the CharacterMesh channel to Ignore and the Pawn channel to Overlap.

This has the effect of my debug point being drawn central to the First Person Perspective Camera. It isn’t perfect but for now I am happy enough with the result to move on without setting the Location and Rotation to the muzzle socket itself.

This is why in a few videos time, you are taught how to implement code on how to ignore the player actor in this scenario. Ignoring Actors In Line Traces | GameDev.tv

You can also manually set collision/event firing archtypes in collision subtypes or in the trace channel itself.

If it’s bothering you a lot, you can skip ahead to implement it yourself.

Overall, my experience with this course (and others) is that the instructor knows where they are going and it’s best to stick the tasks set out in the course and complete them as you go. It’s pretty easy to wander off and get lost.

2 Likes

Privacy & Terms