• News

• Industries

• Learning & Support

• Community

• Marketplace

# Finding the angle between the player and a wall

I’m trying to make a wall run in blueprint where if the wall is in front of the player they will run up the wall, but if the wall is to the side they will preform a wall run. My problem is I can’t seem to figure out how to get the angle between the wall and the player to reliably decide which one to do.

Here is an illustration of exactly what angle I’m trying to get, hopefully it helps.

I’ve already set up a trace for the wall and stored the wall normal and converted it to a rotator, and I’m guessing my best bet is to use the yaw of the player and the wall to get the angle I need, but I can’t seem to figure out how. What is really throwing me off is that the rotator’s don’t seem to be 0-360 like i thought it would, but instead its returning values between -180 and 180.

I’m still learning myself, but what if you added a hit box of some sort on the side of your character and check for a wall collision. This way if the wall is anywhere other than the side of your character he will not attempt to run up the wall. Same thing for the wall up except in the front of your character. Just how I would begin my approach. Hope it helps.

Thanks Gankable for the reply, but I figured it out. I your solution probably would have worked as well.

The way I would try to solve this would be to get the dot product between the player’s forward vector and the wall’s axis vector. That would give you the cosine of the angle between the vectors which you could use in a boolean branch compare with a varying cutoff point. To get the wall vector you could create a vector perpendicular to the surface normal, or you could try to get the wall actor’s Y axis or something (depending on how your mesh is oriented). The second approach would probably be more stable but it depends on the specific project details. You may find that you have to make several traces along the general direction and come up with some kind of average depending on how smooth the walls in question are.

Of course there are probably a dozen ways to solve this problem.

Thanks a ton Ryan, you helped clean up my blueprints a lot. Your solution was way more simple than mine, and more reliable.

I am glad it was useful! Keep your eyes peeled for the next ue4 release in a couple weeks. It will include a content example map called “Math_Hall” that includes a section on intro to vector math. It was designed to help people who don’t understand terms like dot product and cross product to be able to apply them, and it also has some helper charts and material functions using the Pythagorean theorum showing how these concepts all relate.

<3 This will be of great help to point new people to! Thank you guys so much for adding something like that!

I second that, the Math Hall sounds super helpful. You guys at Epic are awesome!