Download

Question about crosshair

Hi everyone,

My game is using some kind of grapple hook, the player can hook himself to only 1 type of mesh.
Player can use the grapple hook on a certain distance. (distance between the player and the “hookable” mesh)

What I’d like to do is having the crosshair displayed on screen reacting (like changing color) when the distance between the player and the mesh is enough to use the grapple hook.

My guess would be to use the Raycast (?) but not sure how I should proceed.

Any ideas on this?

Thanks in advance!

So to actually get the distance of the hook you would use a raycast and then you can just call a function to change the colour of the crosshair.
for the raycast just set the distance it can reach, also when the player uses the raycast call it on a tick so you can do things like checking if the raycast hit an object and if it has change the crosshair colour and if it hasnt set the colour back to default.

If you dont know how to setup a raycast look at “Weapon firing tutorials” most of them use ray casting so you can simply change it to fit your needs.
If you are still struggling let me know and i will create an example for you.

rapiidzz901, thank you very much!
Actually, I’d be really grateful if you could provide some example, don’t have much experience with Raycasts.

Thank you!

Sorry for the late reply, i was quite busy.

Anyway i have four images for you, i hope this helps.

First setup your crosshair in your widget and it sure already be a variable if not set it, then in the event graph you want to make a custom event and add one input which is the colour, type linear colour then set it up like mine is on the image. Then in your character class create the widget (the beginplay image), i made my hook simple but just change things to make it the way you want so for me when the key is held it activates the hook and when the key is released the hook deactivates (F Key image) finally make an event tick and copy what i have. (Tick image)

This is the basics for it so most likely you will have to add other things but this is to make the crosshair react when it hits any object. To make it check for specific objects you will need to use a line trace by objects and then make an array of your objects, i think i haven’t used the object trace in a while.

Note: The float 500 is the distance the raycast will reach, The red colour is the colour the crosshair will change too when it hits an object, The white colour is the colour the crosshair will change too when it doesn’t hit an object.

I tested this and mine works fine so it should work fine for you as well.

Great, thank you very much!
I’m gonna try that today, will keep you updated.

thanks again!