(Finished course) Suggesting a "fire through the gun" challenge

Hello,

Just to clarify, finished the Simple Shooter whole course and posting here as most of the last lecture discussion
appears to redirect to the " Oops! That page doesn’t exist or is private." page. Would move this topic to the very last lecture of this section, once this is fixed.

This course is very cool, and I decided to implement Sam’s switch weapon system challenge, which was pretty ok.
The thing that primarly bothers me however is the fact that we shoot from our camera viewpoint to our crosshair, so I tried looking into doing that from our gun’s muzzle socket to our crosshair instead.
This would fix being able to shoot enemies when your character should hit a wall instead, from its gun perspective.
This would look like the big Tank course (Original version) Aiming part, except in this one we don’t use animations. But the angle logic is there.

I thought it’d be a good idea for people interested in this challenge to share its feasibility and realization in this topic.

From my analysis, here are the modifications required:

in Animation blueprint event graph:

  • Change the way we compute the delta rotator that is used for setting aimoffset variables
  • set Aim Yaw variable too
  • Maybe dont do too much math in the blueprint, nativize in C++ instead ?

In C++ Gun:

  • Make a public function to get the relative angle between the muzzle socket rotation and the (camera linetrace to the crosshair)'s rotation
    In C++ ShooterCharacter:
  • Expose to blueprint a function calling our new Gun function, of our current Gun.

Required other modification after that:
-Firing the gun: we have to modify our Gun::PullTrigger implementation, so we simply linetrace in our gun pointing direction
-We need to disable the aim offset while our character is running, because it looks weird and game is a bit easy if we shoot at stuff while running. Having that,
if we pull the trigger while in our run animation, the character would just hit the floot.

EDIT: Did in a more simple manner actually. See below

Well, it turns out I did it in another way.
I kept the animation BP unchanged, And modified the firing logic of the gun.

Step 1 - Create a new function which purpose is to deproject crosshair to the world
Step 2 - Use FindLookAtRotation to compute the linetrace from the gun’s muzzle to the deprojected
crosshair.

Quite simple.

1 Like

Privacy & Terms