I’m trying to implement a cone trace by using a sphere trace and checking if the hit was within a certain radius, but am struggling to get the math right (I should’ve paid attention in class!). Below is what I currently have.
Any idea what I’m doing wrong? Basically I only want the hit to count if it’s in a 30 degree radius of the hit start (attacking actor basically).
I feel like GetDistanceWithinConeSegment would be invaluable here, but it doesn’t seam to be BP accessible?
MathBPCone.zip (11.1 MB)
A quick exposure of the c++ via a bp plugin I cooked up (UE 5.1). Plugin name MathBP
I don’t know if GetDistanceWithinConeSegment is the solution or not. Would need someone that’s familiar with it to chime in. Seams to give distance from center line and may not work for an in radius check. Your package is also for a different version of UE than I’m using (5.0) as am waiting for other marketplace plugins to update.
I just can’t understand why there isn’t some form of cone tracing built in. My math solution is the right direction, but my math is off somewhere.
Converted it over to UE5.0 and unfortunately doesn’t seam to be the solution or am not understanding how it works.
Got the math figured out. Once I’ve a completed solution will share the BP.
Below is the solution I came up with. Seams to work well. Reviewed the BehaviorTree ConeCheck source code and remade the check in BP.
Basically just do a normal trace. Pass its hit along (IsValid check before passing if you want) and it’ll report true/false if is within your cone radius. It’ll use the trace start/end points to determine the cone size along with your radius. The cone is infinite so you need to be sure your actual trace is as large as you need it to be. I recommend using a Sphere or Box trace for this.
I also added a debug mode to help visualize the hit check and show the cone as well, but you can skip adding that if you don’t want it. I made it a separate function so it’s easy enough to just exclude all that.