So far I have a system in place that uses Single Line Trace by Channel to trace a line out in front of my character to detect simple collision with objects. However, this only works if the objects are on the same Z axis as the starting point of the Single Line Trace. How would I go about accomplishing the same effect but at the same time drawing that line in the direction my character is looking in First Person? There is no way to set any kind of rotation on the Single Line Trace. Any suggestions?
Howdy! I struggled with this the other day, I ran my trace from a camera attached to my player, but I think just using your players position/forward vector should work. I attached a picture of my blueprint, make sure you connect some kind of start event, (I used on-tick, but its disconnected in the screenshot) let me know if you have any questions!
So this will track when I look up or down as well? Interesting. I’ll give this a shot.
Edit: A few other questions -
Where do you keep this? Currently I’m building it in my item blueprint. Should I consider making this part of my Player blueprint and send data to my item blue print when I’m looking at stuff?
Double Edit: So after playing around with the setup the thing I’m noticing is that the Z axis is always 0 because the Roll is always 0. I need to find a way to capture the Z axis as I look up and down.
I have this as part of my player blueprint, the whole “send data to my item blueprint” part is what I’m currently stuck on… But the blueprint above will shoot a trace wherever you look, up or down.
Have a look at the First Person template Blueprint. If you use Get Control Rotation you will get the rotation including the view pitch. The pawn itself does not pitch up and down as you look around. I think you do want the trace logic in the pawn itself and not on the object.
Thanks both of you, that actually worked like I had intended it all along. The issue I’m having at this point is returning what is hit and then triggering events off that.
Once you know the thing you hit with your trace, you can try ‘casting’ it to a particular kind of Blueprint to then fire events on that. A more advanced workflow is to create a Blueprint Interface (e.g. InteractionInterface) containing some event (e.g. OnInteract), add that to any BPs you want to interact with. I want to do a video tutorial on doing this
A video would be very helpful. So I have it hitting ‘worlddynamic’ objects and that works. However the output is obviously not that simple. Instead of it simply being Pickup_Health (blueprint) its something like Pickup_Health_C’/Game/Maps/UEDPIE_0_Example_Map:PersistentLevel.Pickup_C_0’ which when compared using == turns false when compared to Pickup_Health.
At this point, would I just simply use my Blueprint Interface to send this data to my blueprents and then do a simple branch that checks to see if that data is its self?
Ok I’ve figured it all out. First, here is how I made it all work together.
This is in my character blueprint. Its triggered off of a tick event. I used what Venain had showed me and it worked just as he said. It draws a line from where I’m looking, out to a set distance. From there, I return the bool from the Single Line Trace for Objects in to a branch. If True, I trigger an event on the Actor Hit. If its false (if it doesn’t hit an object) it sends a bool of False to the players HUD.
Because of the blueprint segment I showed above, when my Player is looking at an item, it’ll send information to it. I then use that trigger to send information from my Item to my HUD. This information is placeholder at the moment. It includes an Item Name, Type, and Discription. In the future I’ll be able to use this to display detailed tooltips about items and objects you may be looking at.
The last peace is the HUD. Here I check to see if I’m hitting a target. This variable is set back in my Player blueprint as well as my Item blueprint. If the item detects a hit, it sets it to true, which draws the UI. If the player doesn’t detect a Hit it returns False and turns the hud off. With this basic setup you could create some interesting tooltips based on what your looking at, with all the data for that object displayed in the object itself. I expose the Name, Type and Description variables in my Pickup_Health item so that they can be modified in the world editor. You can see how this all works below.
And here is the results!
When you look at either item you get a different set of text based on what was set in the world editor.
When you look away the tool tip instantly disappears.