EDIT: As I found a solution to my first question, I’m changing the question to just focus on my other question.
I’m looking for a way to reliably do traces in a cone from an object. In my project I’m using a Behavior Tree, and as the Cone Check decorator comes with it, I was wondering how it works. I can’t get it to function properly, even as I have created a debug cone to help me out with the matter. As there is no way to properly debug it, I have no idea how to make it work properly with trace blueprints.
My question is: Is there any way of having some reliable cone tracing in UE4? Cone Check has been working sporadically, but I’d like to know if there was some way of just having a Cone Trace?
Just a question, because maybe i get wrong what you want.
A cone trace, for example, would be the view field of a character?
And you have come up with a solution for this trace but it doesn’t rotate with the player/object? So it updates the position but not the rotation?
Isn’t there an easy way to just get the rotation of the object and apply it to your cone trace thing?
Exactly a view field.
Getting the rotation and applying it doesn’t work as I have already described.
Bumping this in hopes that someone has an answer. I’m stuck on this.
Please do not bump threads that have not gone unanswered for at least four days, this clutters the answerhub and makes it very difficult to parse through and help anyone. Thank you.
this is just something i came up with in a few minutes.
I used a for loop to make 5 Single Sphere Traces and used some math to position them
each a bit further away from the character and also to make them bigger. I added a short distance between the start and endpoint, because otherwise it didn’t want to detect colisions.
I guess there is a better solution, but maybe this gives you an idea on how to do it.
And the Blueprint:
If you have questions or if you want to discuss this method, feel free to ask me.
If you plan to make a bigger discussion about this topic, please stick to your forum post.
That looks like a really good compromise!
Would the performance be in any way a problem here?
I don’t think this will hurt the performance, since you are told to use the shaped trace for a vision cone in the documentation. But i think it can be done better as i did. I just tried to make a fast simple example for you. You just need to fill the cone you have in mind with some simple shapes like the sphere or the box. I thibk i will try the box later the day after work to fill the gap between the eye and the ground directly in front of the player. Maybe the box has some more usefull settings.
I guess you could set the start point above the eye height and the end point beneath. Then you just subtract the radius to get each spherer on the same height.
I think the way you did it is honestly the most “natural” way. If the eyes look slightly down (as they would in real life), this would also taper the vision towards the end of the sight range.
I think boxes could be cheaper than spheres potentially, if only through the use of simpler geometric shapes. Incidentally they might also fill in the small “gaps” between spheres where the pawn in question would not be permitted vision. I’m going to set up the sphere version later for testing.
To fill the gaps you only need to choose some factor better than me.
The thing is, it’s up to you if the NPC should see people in front of them, even if they crouch under their eyes, or if they should only recognize them, if they see them like the way i did above.
Most of the times (if i look at actual games) the NPC sees you as soon as you run into his view cone. So for this it would be better if you move the first 2 or 3 spheres from top to bottom, so that you can’t crouch directly in front of the NPC without getting noticed.
I don’t know if you can make the box something differ from a³. So that you make it a * a * b and b is the height, so it would always be as heigh as a character.
If you are pleased with my answer, feel free to accept it by pressing the check mark at the left side. (:
I think the way the spheres work right now, even in a crouching position they’ll be able to see you. That being said, my responsibility in this is just to provide a rough AI - to which end this “cone” will suffice.
Thanks for your time, and feel free to respond with the cube version here as well! =)
I’m actually running into a problem here as the enemy’s vision seems to never be limited to just the cone. Instead, it seems to be able to see me anywhere, even if I am not inside the “cone” of vision. What’s wrong?
Just to clarify, my setup is the same as yours blueprint wise, while I’m using a third person setup instead.
The thing is, you need to specify what the trace actualy traces. I set it to “visibility” so it will also trace the ground for example. You need to use custom channels for your character and only trace them. You can also make an object trace instead of a channel trace and specify the object (“Pawn” for example).
So at them moment, this setup traces everything visible and will only ignore the air. I made it to get the cone shape. You need to adjust it for your game.
Well I used “camera” as the channel. I don’t know what the difference is though, it seems both of them will look through any obstacles. I don’t know how to make it so they would work only in their vision radius. Camera previously worked when I used a two step trace (large multi sphere + single trace camera vision).
There’s also no documentation on this exact point so I’m at a loss.
You just need to specify what the trace should look for. I normaly use the Trace by Object instead of Channel. I create an Objecttype in the Projectsettings for the Object i want to get traced and set the object collision settings to block this Type. Now i set the Tracefunction to also to the Object Type. You can test this with “Pawn” or something. Now the Trace should only recognize the Pawn or Player or what every you want to track. The name of the type can be anything but should be named well suited like a variable in coding
In this case I would probably have to use both though, at a huge performance cost as the cone is large enough to be able to see through walls – if I pick object. That is why it would be better to pick camera that in my previous attempts blocked vision in terms of BSP, but does not seem to do so when it is based on the sphere-cone…
Ah you are right, this could still look throught walls. What if you do a line trace from the NPC to the found object by camera to make sure there is nothing in between? So for example you have an NPC and your Player. You let the NPC find the player with this Sphere Cone Trace. Now, after you found him, you get his position, and trace from the NPC to the Player with a single line trace (shouldnt be a high performance cost) and check if there is a wall in between.
That sounds good in my head xD
That’s what I have been doing, but that is so expensive performance wise that it lags up play in the editor - and that’s just for a single pawn.