Check if a line trace hits an object or trigger.

Hey

I’ll add another thing while Im at it. =) Does anyone know how to check if a line trace from the character hits a specific trigger or object for that matter?

Thanks

1 Like

I’m assuming you know how a line trace works already, so I won’t go over that. From the Out Hit node, drag out and click on Break Hit Result. From there, there are multiple ways you can check for a specific trigger or object. If you drag out from** Hit Actor** and do a Cast To, you can check to see if the actor you hit is a child or member of a certain class. In this case, I’m checking to see if the Hit Actor is of the ThirdPersonCharacter class. To check for trigger or collision objects, you do the same thing but you would drag out from the Hit Component node. But mind you, this would activate following code if other objects that you did not intend to activate also have the same type of collision objects, so you would have to check for the parent actor class. The other way you could do it is to simply drag out from Hit Actor or Hit Component and do a direct comparison by typing equals or not equal.

1 Like

Im looking into it now so Im rather novice and if you know how I would appreciate the help. Im trying to get a line trace from the weapon that the player is carrying to an object or a trigger that will activate something in the environment. Would work sort of like a remote control for the TV I guess. Could open doors, extend bridges from switches on the wrong side of the gap and so on.

Thanks for answering so quick.

Is there a way to see if a trigger is hit by a certain type of weapon? And if so how can I set that up cause it sounds like that could be the easiest way to do this?

Yep you just cast out to your weapon on the collision, same as you do with the line trace break result posted above

I can’t seem to get it to work properly. I can do the line trace fine but it doesn’t detect the object I have assigned to it. Can anyone tell if there is something wrong with this setup? I have tried with cast to on a character and other objects and a trigger but with no luck.

So here is what the Collision Details box should look like.

Collision.PNG

This goes with the message I sent you.

Could also only paste it here for some reason. So this shows my setup in it’s entirety.

1 Like

Wait where is this code located? Is it in the cube’s blueprint or in the FirstPersonCharacter blueprint?

If this is in the cube blueprint, you have to uncheck the box that says Ignore Self. Because if you are trying to interact with the cube but you are ignoring it, it simply wont react.

Having ignore self unchecked didn’t work Im afraid. It really sounded like it would. I placed it in the level blueprint cause I didn’t know how to reference the cube inside the character blueprint. It works perfectly without reference so I don’t get it.

OK. The solution is in this video. It’s super simple as usual… when you know it!

Now I just have to figure out how to send the trace result when successful to my level blueprint. If anyone knows how then just let me know please.

In 4.9 you can Cast to your level blueprint. In previous versions you couldn’t. So if you just upgrade to 4.9 then you should be able to do a regular cast to im pretty sure.

I know im 5 years late on this one but what I did was a cast to my enemy blueprint and then i used the ‘cast failed’ to execute some code. Basically you can use the cast as a true or false statement. If the cast is successful then you can execute code from the main pin, if not then you can execute code from the ‘cast failed’ pin.

You can? How? Im not seeing the node