top of page
Search

Dev Log 10# Learning about LineTrace, Using a Multicast RPC and debug sphere act as a temp crosshair

So firing a gun in a multiplayer shooter game is probably the most important mechanic, what's also just as important is letting the whole lobby know where the gunfights are taking place as they'll want to head straight to where the action is. This is where I used a multicast RPC as by calling these on the server they invoke on all machines that are in the game. However these must be called on the server if they are simply called on the client they will only be executed on the invoking client so I also included a server RPC which is being called on the client and that simply calls the multicast RPC so that the multicast is being called on the server.

The shoot function just handles playing the animations for character and weapon at the moment implementing damage and health is on the to do list though.


I also learnt about line trace in unreal engine https://docs.unrealengine.com/5.0/en-US/API/Runtime/Engine/Engine/UWorld/ this documentation page is great as well as the blueprint version https://docs.unrealengine.com/5.0/en-US/using-a-single-line-trace-raycast-by-channel-in-unreal-engine/.

If you peek the definition of these functions you will see that these are raycasts which are commonly used for collision detection and shooting a weapon is simply another form of that as the weapon needs the line trace to detect if its hit something.


Unreal provides line traces that can be single by channel or multi by channel as well as single and multi by object or profile. If these line traces are blocked by something that hasn't been specified to collide with that line trace, the functions will return that blocked hit, the single line traces will return the first blocking hit. Whereas the multi line traces return all blocking hits in the form of an array and the closest blocked object will be the last in the element in that array. So essentially if you have objects that are lined up behind each other the multi line trace won't return after hitting the first object like the single line trace it will go through to however many specified objects are behind the first one. I imagine this is how getting collateral kills work in video games by setting the player characters to be detectable objects for the line trace and then applying damage to the array of blocked hits which in this case would be the players.


Now at the moment I don't have a crosshair implemented yet so how do I show where I'm aiming, a temporary crosshair solution that I found was to simply draw a debug sphere at the Line Traces Hit Result's Impact point to visual where the bullet has travelled/will travel. A bug that I found when testing this was to do with the UI Overhead widget that I have which currently displays nothing. As you can see from the video below when the player looks straight up and shoots, the debug sphere appears right next to their head because it's colliding with the UI widget but it was a simple fix from the blueprint end's by turning off collision in the Overhead Widget Blueprint



 
 
 

Comments


bottom of page