Hi,
I currently have a line trace and a camera shake that emulates weapon sway/stability. My problem is that now where the camera sways, the line trace still fires directly into the middle of the screen. I plan on adding this kind of mechanic like the Evil Within games.
The camera shake component is attached to the gun parent.
The sway is slightly exagerated
.
Iām sure thereās something here I could add to fix it, but if anyone has a better solution then Iām all ears.
The sway is also dependent on the var Stabilty Float set in the gun children, hereās the full line trace
Third person line traces are a bit complicated, but it generally requires at least two different line traces depending on what you are doing. A simple weapon firing system is something like:
One from the center of the screen forward to a fix point in space or until it hits something and then another starting from the characters weapon muzzle and ending to the point in space from the first line trace or whatever hit location it has referenced. Given that your screen is moving with camera shake to emulate weapon sway you should still be safe to approach it this way.
There are other posts on this forum with screenshots already posted that should get you started, but unfortunately Iām not able to point you directly to them at the moment.
1 Like
thanks for the reply,
I took your advice and added a second line trace which spawns from the barrel. When the barrel is blocked while looking round a corner for example then the object in the way of the barrel is shot.
I pluged this after the existing line trace above
Iām still having issues getting the line trac to match the camera shake though, Iām not really sure why would I have to create a third line trace for this?
I have a similar third person setup, but without the camera shake. Iāll try and post an example a little later how it works. I donāt see why it wouldnāt work with the moving camera though. It uses converts screen space to world space by dividing the viewport by 2 to arrive directly in the middle and getting that location for the starting point for the first trace, so it should match wherever the viewport is located in that moment in time.
1 Like
thankyou,
might be worth mentioning but I created my own legacy camera shake class and only call it when Iām aiming
Here is my magical line third person trace system lol. There are a few things to consider with it. One being the impact point and impact normal on the lower right corner of the screenshot have the values tweaked slightly (-1) because for some reason sometimes the line traces fall slightly short of the blocking hit and this ensures you can get a reliable hit result off whatever it is hitting. i.e. bonesā¦
The second being in the sequence node the āthen 1ā output is essentially just running straight into the top line trace node. I just have extra stuff going on above it that is irrelevant to this topic. Also the client play force feedback is if you want to add rumble to controller and is also irrelevant here and you can just skip that too.
Thirdly, you should also consider that with third-person perspective your traces can be blocked by objects in front of the characterās weapon/body. Other considerations should apply to accommodate pushing these traces forward certain distances so that you donāt first hit objects behind the player in the forward direction. It will basically shoot anything that the reticle hits either behind or in front of the character unless you adjust that.
The out hit on this function you can plug into whatever damage system you have set up and break that hit result there. I highly recommend ignoring self or you will likely just be shooting yourself and turn on the debug while testing this or you might end up really confused.