I have a thing I’m developing, and have been struggling with trying to figure out a certain system I wanted to implement. In essence, it’s a top down game (using the third person template) in Unreal Engine 5.1, and the player rotates toward the mouse. What I’m trying to do is make it so the player can block while holding left click, and if they’re hit by an attack in that direction, it will successfully block it. But if an attack comes from say behind or to the side, it would still hit them.
I’ve set up a bit of code as a base where it will block attacks from any direction, but I want it to only be in the general direction the mouse is facing, and thus the player is rotated toward.
I should note, the enemies are using a line trace to attack the player.
If there’s any questions for clarity on the blueprints I’m using, I’m happy to screenshot them and send them over.
Just one question for clarity, the Less Than node, with the 0.9 value, would bringing it up/down increase how much sort of room for error in the trace would exist? Or how exactly does it affect the dot product?
Yeah, that it kinda what I was aiming for. So, what part of the enemy should I be tracking for it to properly be facing the player? The Trace Shot? I left the Get Actor Location as self since I kinda assumed from the above layout that you were just using a reference to the cube as itself for it.
Enemy forward dot player forward. This will tell you how well the enemy is facing the player - can they even attack. Then you can do another dot to figure out whether the player can block it.
So, in essence, I should change the Get Actor Location for the enemy to a get forward Vector for their mesh?
I’ll note, all I really need to know for the Blueprint I believe, is if the player is actually facing the direction of the enemy that’s facing them, so I can just turn that into a Boolean for if the damage will go through to the player or not on a branch if they’re guarding toward them.
Ok, so if it’s 2 seperate checks to try and do that, is there a way of just making it one check for if the player is facing toward the enemy? Like, a way of having the dot product track just the direction the player is facing, and the location of the enemy to make sure the player is looking at whoever’s attacking them? Because I tried setting it up as you showed, but I can’t get the actor location of anything in the enemy outside of just the self reference.
The attack itself will be a form of communication that will produce either the reference of the attacker / defender, or the data. Line trace will give you direction:
When the enemy gets close to the player, it uses the line trace by channel node shown in the image, and if it hits the player, it casts to them as the Out Hit Hit Actor.
I have the below set as you said to get the line traces direction, and the players forward vector. But again, still always triggering the damage and not blocking no matter what way they face in testing.