In Verse UEFN, you can detect where a player is looking by using the find sweep hits function, which performs ray casting from the camera position along the player's view rotation to detect what they are looking at; this technique requires using LUF (Left, Up, Forward) spatial math for scene graph operations, and can detect entities, props, and devices but not static meshes, allowing developers to trigger actions when players look at specific objects.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
How do I know where a player is looking and do things based on that? Simple raycast in Verse UEFNAdded:
What's up guys? Uh I'm here with today's tiger bite and a few people have been asking me how you can detect what a player is looking at on the screen and do things with that. Uh so the answer in scene graph is uh we use a function called fine sweep hits and it's a form of ray casting. So if I walk on this trigger here and activate it um and then I use my aim button because that's what I've uh partnered up with you. Can you see these yellow lines? Every time I click aim, you get a yellow line and that's the sweep hit that I'm currently uh carrying out. So, um, I'm currently sweeping from, uh, the camera position to where the player's looking.
Um, and you can see, um, I'm only drawing the line if it actually finds something. So, uh, I draw and it detect the floor or it can detect a player build or it can even detect Peely here.
Um, if I fire it here, you can see it's not, uh, detecting it.
That's because this is a static mesh.
Uh, and it can't detect static meshes.
can only detect entities, props, and devices uh with the sweep here. It didn't used to do props and devices until recently, but you can see if I hit that uh that from there, it's drawing a line from my camera to the thing it's hitting. Uh and then we can do things with it. So, for these uh entities over here, well, here's P. Um but for these entities here, uh if I just look at them, nothing happens. But if I, uh do a raycast to them, I turn them red. Um so, I will go through in the code how to do this. Uh, and you could do lots of other things with this. So, uh, as you can see, if I just look at it, nothing happens. If I, uh, click near it, nothing happens. I have to be looking directly at it and click, and then it turns red.
Uh, and there's other things you can do with it. Let me just turn on the other ability. So, um, what I'm doing now is, um, when it hits something, I'm going to teleport a carriable to it and explode it. Uh, so poor peeling. Uh, now the aim button teleports one of these carriable spawners to it and explodes on his head.
Uh, and we can use that to damage player builds or just keep killing with it. Have to put it to your feet.
So, it's just a real useful little technique we can use with scene graph to uh uh to see where the player's looking and do things based on what they're looking at. Okay, let's look at the scene.
Okay, this is the scene today. There is a little bit more than normal because uh normally they're completely empty at the moment. Um we've got two triggers. Uh they were to activate the uh different things. So the first one activated the raycast, the second one activated uh the carriable spawner. Uh there's the carryable spawner device which I was using to explode on things. Um two player built walls which I just built in the edit session so they stayed there.
And then these five little entities.
Now, as you can see, there's nothing on these entities here other than uh a mesh component. And the mesh component is literally just from my uh from my mesh folder. It's just a little uh cube I made. It's literally just a static mesh uh that I modeled and then put into an entity um that I call material box because I was using it to show how we change materials on things. Um, I'm trying to think of any other setup that I might have had to do to demonstrate this. Uh, so I placed down a carrierable spawner and turned off spawn automatically and respawn automatically because I'm going to handle that in code. I don't want it to be spawning things for the players to pick up. Uh, if you were doing this really, uh, you would probably turn off can be thrown and can be dropped um, so that they couldn't uh, pick it up. You can change the amount of damage they do here. Um, there's lots of uh, you can even like add an impulse. So you can set it to no damage but add an impulse. So you can use that to propel the player where you want them to go. Um so there's lots of fun things you can do with this. Um but I'm just demonstrating the main thing I wanted to demonstrate today was the ray casting. Um so okay so let's have a look at the verse. Um oh uh there is also an entity in the scene over here. It's an invisible one. Um that just has this raycast component on.
And as you can see all I've got is my two triggers. uh the input trigger, which is aim, which I was using to activate this. Uh you don't have to use an input trigger, by the way. You can have this looping. Uh I wouldn't loop it too often, but you can have a raycast looping all the time, so you can always detect where the play is looking. And then there's the carryable spawner there. Right, let's look at the verse.
Um okay, so here's the verse. So, uh little bit different today. So uh because I'm using spatial math and I'm using characters as well because the fork character the fork character uses XY Z uh which is the old type of spatial math and scene graph uses LUF left and forward which is the new type of spatial math. Now you can import both just as the way up here. Uh so I could have just put using and put this old version in there. But if you do that then every time you try and define a transform or a vector 3 or something like that you have to specify which of these is and it's really annoying because you have to copy this entire uh thing and put it in brackets in front of like transl transform or translate any vector 3. Um so what I do is I import uh one as the using. So I always import the new one as the using and then uh I set the old one as an import like this. And what this means, uh, I'll talk it through when I get to it, is that if I ever need anything inside, uh, this old math, uh, I can just call it with XY Z. Uh, so, um, and then the other thing that's different here is, you remember those yellow lines that I was showing you. Um, that is called a debug draw. And, uh, you have to set it up like this. So, outside your component, set up a a debug a new class of a debug draw channel. So, I just called it my debug draw. um debug draw channel.
Um is there anything else? I think you might have to turn that on in island settings as well. Let's have a look.
It's been a while since I've uh fiddled with the uh island settings. I think you might just have to put debug mode on in here. Uh VSTs debug draw here. Look in island settings. Just tick that and then those little yellow lines will appear.
Um okay. So let's go back to the verse. Um so that's how you set up your debug draw. uh channel. Uh so then we're into the component itself. So I have my editables which I showed you in the actual thing which is just a trigger device, another trigger device, an input trigger device, and the carriable spawner. And then I just define debug draw as a debug draw using that channel that we defined up here. Um I have a variable which is a logic variable for bomb. That was just so that I could uh turn on and off that uh carryable spawner explosion.
And then uh down here uh we've got the normal on begin simulation where we just uh super on begin simulation. And then on simulate I spawn my trigger await which is waiting for um so I did I I demonstrated both different methods here. I wouldn't normally do uh both different methods of uh subscribing or awaiting um but I just wanted to show both. Uh, so the first trigger I um spawn this trigger await function. And what that does is I'm just waiting for the trigger to be functioned. It's a suspend function. Um, uh, so it gets to here and then just waits. So it's waiting for the trigger to be um to for the trigger to be triggered. Um, as always, it's a maybe agent from a trigger. So I just define if it is a um if it is a real agent, and then I register the agent to the input trigger.
And then I spawn this looping function which is what detects the rate casting.
We'll cover that in a second. The second trigger, I could have done the same again. Uh I could have waited for it like this, but I want to show that you can also subscribe to these things. And if you subscribe to the trigger, you put in the maybe agent in the function name itself. Uh in the definition of the function, not the name, sorry. So it's the same thing, but I'm just uh defining it in the different ways. And all I wanted to do with that second trigger was set that variable up here to true.
Um, and then I handle the rest of it in the code later.
Okay. So, uh, after I give them the input trigger so they can do the ray tracing, we spawn this input await loop.
Um, so in this loop, I I call the loop and then immediately wait for them to press the input trigger. Um, and then as soon as they press the input trigger, it moves on through here. So I get their four character. Um because to get things like the view rate where the player's looking or anything to do with the character, you need the fork character uh part of the agent. Uh so we get the fork character and then we get their view rotation which is fork character get view rotation. That's the function there. But do you remember I was talking about the uh difference between XY Z and LUF. um we need uh LUF for uh sweep hits to do uh anything with scene graph you need LUF. So what I've done here is I'm using the from rotation function that's inside that uh Unreal Engine the the old spatial math. So to call it it's XY Z from rotation and then put in my function. So this is the function that calls it. Um and then if I want it to be in LUF use the from rotation function.
Um, so I'm looking where the player is looking is get view rotation. Uh, and where they're looking from is get view location. So you've got rotation and location. Um, and so what I'm saying here is, uh, the view transform is a transform with translation of view location. So again, we're using the from vector 3 um, to convert from XY Z to LUF and we're using that view rotation there.
Um, I probably actually could have just put this inside here. Uh, I don't really know why I didn't, but um I could have put this function inside here. Uh, but basically I'm just defining the transform where uh the view is coming from. So it's it's coming from uh the camera. This is what get view location uh gives you. Uh and where they're look the angle they're looking is the rotation. Um and then uh what I'm doing then is I'm I've called this hits gen because it returns a generator.
Everything in scene graph returns a generator um which you have to for loop through. Um so what I'm doing is from the well it's not from the entity but I'm using this entity I'm going to find sweep hits uh and I want to um find it down the forward axis of the entity of 3,000 not of the entity. So forward 30,00 uh and I want it to start from this transform that we've declined uh defined here the view transform rotation. Yes, sorry. So I want to look forward along the forward axis 3,000 units. You can change this if you want it only just to be a bit closer. Uh four uh 3,000 units down the forward axis of that rotation that we've defined here.
um from the place that the camera is.
Um and with this find sweep hits function, uh you have to say what you want to use as the collision volume. Um so we're just using a default collision point.
You can use a sphere if you want it to be a bigger thing if you want to uh you can sweep anything. Um but I'm just using a collision point because I don't really I want it to be exactly where the player's looking. But you can you can sweep a mesh down there. Uh so you can see what a mesh would hit if it went uh down the sweep, a capsule or um a box or a sphere. And you can you can set the how big they are with using these, but I just used a point. A point's generally fine for what we're trying to do here.
Um so that returns this generator, but I don't find generators very useful, so I turned it into an array. Um so all I did was loop through the array. So for every single thing in the generator as a hit do hit. So I've now got a hits array which is an array of sweep hits. Um because find sweep hits returns a sweep hit. Um let me show you what a sweep hit is. So this find sweep hits returns a sweep hit. And a sweep hit uh has lots of things inside of them which is here.
Um, so it tells you I don't really use source very much because I know what I'm sweeping down it, but targets really helpful. So target component is the thing that was hit by my sweep. Um, haven't used volume. Uh, contact position is where the thing's hit. Uh, the normal as in the 90° from where it's hit. Um, and the contact face. So like where on the where on the face it is.
So it's the most opposing face normal of the faces. Uh I think if you needed to use these ones you would know the one I use mostly is target component.
Um so what I'm saying is for the first hit so it it returns um hits in order. uh if it if you are sweeping it will carry on through um everything until it hits something with collision block. So if you have uh 10 10 entities lined up in a row and uh nine of them overlap all and the last one is block all um it will pass through all nine before it hits the 10th. Uh so all 10 will be in the array.
If you have um the first one as block all it will only return that first hit.
Um, so all I'm doing here because I don't know what collision player builds and things are, um, is I'm saying that the first thing that it hits, so the very first thing in the array, because that's the other good thing about sweep hits is the array is in the generator and therefore the array is in the order of it, the things it hit.
So get the first hit from there and then I want to draw a line using that debug draw. So debug draw draw line from uh the camera the view x form translation to the first hits contact position. So where it hit the first thing.
Um so that's just so I know what it's hit. That was that yellow line. Uh in a game that will not show. This is just for us to debug it. Um and then I've got a couple of if statements. So that draws the other line all by itself. Uh, and you we now know that this first hit is the thing that we were looking at, the first thing we can see that it touches.
Um, bearing in mind the collision profiles that I said earlier about static meshes, it doesn't detect. It has to be a prop or an entity or a device.
Um, okay. So, next, uh, I did two different things. So, I said, uh, if it's, um, if the thing that it hits is one of those material boxes. So if it was this static mesh here, if it was a mesh component with that static mesh on it, um then do stuff to it. But the way you say if the thing it hit equals that is you have to cast everything in scene graph is casting. Um so I'm casting the static mesh which is uh meshes uh material box at that component there. So first hit uh is the sweep hit and the target component from it is the mesh component. So what this is doing is saying if this mesh cast to this target component. So it's basically saying if this if this mesh component is this uh and it's I don't really like the way uh mesh components work and how you have to do materials on it. Um but this is what we're with at the moment uh with no set material function. Uh so then I define um a new material instance. I set the box material to that. So, um, material zero is the material slot name of that box that I made. Um, so, uh, you remember I changed them to red. So, I'm setting the material slot of that mesh component to this new material instance. And then I'm setting the color of that material that is just a parameter in that material. I'll show you in a second to uh named colors red.
So uh in verse uh they define a load of colors we can just use and then you don't have to worry about making uh your own color. Um so I just said uh just use name colors red.
And then uh the other thing uh I did was I said if bomb equals true. Uh that is another way of writing uh bomb equals true by the way. Um you can also do that but just short neater to use the question mark. If I want it false, by the way, it's just not bomb.
Um um so if bomb is true, which it it is if we've stepped on that second trigger, remember that's how I set it true.
Then um I set the carryables global transform. Uh so I don't know if people are aware of this at the moment, devices and props now have this set global transform which was previously just for entities and it means you can use LUF without conversion. Um so all I've done there is set global transform uh of transform. So this is yet another way of uh writing. So you see here I did it um like this. So I could have defined a transform in this way but I decided to show a different way. So of transform and then the translation is just this uh contact position of the first hit. So, basically, I'm moving the carrierable spawner to the place that the the uh that the sweep hit hit uh the the raycast hit. So, I'm moving uh the carrier spawner to there and then I spawn a new one and then I explode it immediately. Um and that just uh was how I was damaging things. You could do the same with an explosive device if you want. I prefer the carriable spawner because it works on shield damage numbers whereas the explosive device doesn't.
Um, and uh, you have to reset the explosive device and things. The carriable spawner is just neat to uh, and you can also hide uh, the VFX and things if you want. I didn't do any of that on uh, my carriable spawner. I just left it as defaults. Um, but you can put your own mesh in there. So, you could teleport your own mesh in there. You could do your own sound effects or VFX in there, but I just left it because it's just a demo. Um, and that's it. So, that's how to do a really simple raycast. Um, so really the bit that's uh important, this is how you get where the player's looking. This bit here, uh, all this was just me showing some, uh, examples of what you can do with that, uh, hit once you've got it. But yeah, that's how you get to what the player's looking at. Uh, I hope that was helpful, guys, and uh, we'll see you for next time for another tiger bite. Bye.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
🚀 BCS613C Compiler Design | Module 1 to 5 Schema Evaluation 🔥 | VTU 6th Sem 💯 #VTU #bcs613c #exam
Pranavaa-y4y
104 views•2026-06-02











