Sorry for rookie question but I don’t have a clue how to do this. I have an object and I want to trigger that when player watching on it. How can I make it?
I think you would have to cast a SingleLineTrace from the camera position to the camera forward vector multiplied by the length you want. Then you break the hit result, get the hit actor, and call the event on it to do whatever you want.
Check this tutorial : https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseRaycasts/Blueprints/index.html
Thank you very much! But I missed how change a length of this SingleLineTrace? This is endless line?
I’m not 100% sure about this, but I think you can’t have an infinite Line Trace. You might multiply the value of the camera forward vector by a finite length. Exemple : multiplying by 10 000 the vector will get your trace going to 100 meters. Try different values according to what you want to achieve.
Thank you!
Line traces work if you want to make sure the player is exactly facing an object.
If you wish to check if the player is somewhat looking in the object’s direction, you can get the dot product of the camera’s forward vector and the look at vector from the player to the object (using a find look at rotation node). A value close to one means the object is in the center of the screen.
I don’t quite understand that way of doing this. We casting two vectors: from the player to the camera point and from the player to the object and after that calculate angle, and when it’s close to 0 then facing to object?
I think it’s not good it that way - if are many objects on the level, we must cast vector to every object? Isn’t it hard? Maybe I missed something?
@ : Very interesting ! I think I could use this in my game at some point.
@ : Not exactly. says that you should get the forward vector from the camera (in order to know exactly what the center of your screen is looking at), and a vector going from your camera to the object. With a dot product of the 2 vectors, you can know how much you are close to perfectly-looking-at-the-object : if 1, it’s perfectly, then you get lower and lower numbers as you move your sight.
As said, it’s useful if you want to know “how much” you are looking to the object, in order to do something if you are somewhat looking at the object (ex: like Boos in the Mario series, that cover their eyes and stop moving if you look at them). If you want to do something when your exact view center is on an object, use Line Traces.
By the way : yes, you will have use these vectors for each “lookable” object. Although, you can cast a single Line Trace, get a look at this video tutorial : - YouTube
Then, Line Trace are good only for single object? When many objects on the scene, cast vectors on each one is not good way of doing this, am I right?
Yeah, I got it after your explanations. Thank you!
Have you seen the video ? It shows you that you can interact with (or look at, to match your needs) several objects using only one Line Trace. And by the way, you will have to use more vectors if you want to use 's version.
I think we are running in circle, it would be great if you tell us what you are really looking for :
- You want to do something when your player is actually looking at an object, the screen center being inside the object’s bounds ? : use my version, with line traces (and watch this video, it will help you)
- You want to do something when you are looking enough at an object, when you are somewhat facing it ? : use 's version, with vectors dot product