Crosshair showing when hovering over interactable objects.
Hey. I'm trying to make a system, that will let the player interact with certain objects. The interaction itself works but i need a way to tell the player which objects he can interact with. I made it so that when the player hovers over something interactable a simple dot appears. The issue is, once this crosshair appears it never goes away.
Interaction is based on linetrace inside character blueprint. It works all the time, checks if it hits anything and if it does it calls a function in interaction blueprint interface.
The interface is simple, it uses only 2 functions.
The switch blueprint uses this interface to toggle light visibility.
And here is my HUD.
Nothing I tried works :/
asked Feb 25 '16 at 01:52 PM in Blueprint Scripting
Ok, i found a sollution. The thing is the "Draw Croshair?" variable inside HUD blueprint was set inside switch blueprint. But when i was looking away from it there was no way of making it switch the variable to false.
HUD stays the same i just removed the "Interaction Possible?" function from interface and switch blueprints. New character blueprint looks like this:
Now the line trace checks if it hits anything and if the object hit uses the correct interface. If both of these values are true it tells my HUD to draw a crosshair.
answered Feb 25 '16 at 05:34 PM
The mechanis may seem easy, but in the background it requires some work.
Ill try to explain
First I made function where I can build it up in without filling my screen to much, PlayerLookingAtInteractiveObject
I dont want to line trace to happen when the player is standing still, so the function PlayerLookingAtInteractiveObject is used in the player movement controls, like Mouse and WASD input.
Then I made a new function called LineScanInteractiveObjects, which does the actual line tracing.
The received results of the Linetrace are then used in a different function to DefinePlayerAction As the traced actors have their own tags, I can use these tags to see what action can be performed with that object. In my example, I only have a lightswitch
In order to get the Widget to pop up and tell you that you can perform an action, I've made a Blueprint Library function that casts for a widget and then set the text variable. I've used a DataTable to store the texts in, as I'm way to lazy to hard code it. Using a DataTable, all you've to remember is the Row Name and what Text was there.
So now that we have LineTraced a object, found it has a tag, displayed a widget that you can perform an action, enabled input, now we just need to handle the players input to perform the action. Which is the easiest of all.
answered Jan 16 '17 at 10:17 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here