How do I make a gun shoot using Line Trace and Impulse?

Hi.
I’m new to the Unreal Engine, but I know the basics.
I’m trying to make a shooting gun using line trace and make it interact with the environment (like in the FirstPerson Template but without bullets). Ok so I’ve created a blueprint, but it does’t work. Here you can see the blueprint

So the line trace works, but it doesn’t interact with anything.

I believe you need to switch it over from “location” to “Impact Point” on your break hit result.

Tangentially, you probably also want to check to make sure the target is “Is Simulating Physics”, right before you actually add the impulse.

e:
I think you also want “Hit Actor” not “Hit Component”. Actor’s are the things that exist in the world, components are the parts that make up the actors. So if you are trying to push something around, you probably want to hit the actor.

Ok, so I changed the location to impact point, and I added the “Is Simulating Physics” node and it still doesn’t work. Also I tried to change “Hit Component” to “Hit Actor”, but it didn’t let me do it. It gives me this error.

I’m not sure if I’m using the correct “Add Impulse”, because there are lots of them. I’m using this one.

EDIT: I also tried to add the “Add Impulse” node by holding down the “Hit Actor” value but it shows me that there’s no such “Add Impulse” that uses the “Hit Actor”. Screenshot.

Ok it works. Thank you for your help.

Can you also tell me how can I make a good visual effect for this (for example a line of smoke going from the camera to where the line trace pointed)?

For working with the hit actor you would need to cast it to a staticmeshactor, then work from there. But that is probably more in depth than what you actually need for this.

You want to use just “add impulse” not “add impulse at location”. I had a chance to load up the editor and this is working as expected for me.

Pull the location node off the break hit result, and spawn an emitter at location. That will let you do an effect at where you hit. You may also want a play sound at location as well.

For something like a line of smoke, you could probably do something with a ribbon emitter.


Alternatively, spawn an invisible actor that is the length of the line trace, apply the appropriate emitter to it, and then destroy it to make it go away.

I would suggest using line trace for objects and adding something like world dynamic, pawn to the object types Array.
See attached Image for your add Impulse at Location. But yes, you could also use add Impulse but I don’t think you could Controll the power of your Impulse with that way.
PS My adding of an Offset for the starting Point is beacause I’m Shooting out of my test character and he has a weapon - so it would collide with the weapon without this hack.
I’d like to suggest you to set a breakpoint add the add Impulse and check the hit results of your trace if you still have issues.
The target must simulate physics and you must adjust the power of the Impulse according to the mass of this object to push it.

Thanks for your reply, but I think there’s a way to do it much easier, because the solution shown by Morkath works perfectly.

Thank you :slight_smile: