How to add a weapon to a vehicle?

I’d like to add a projectile weapon to my vehicle, how can do I do it?
I don’t need to physically add the mesh for the gun, only the projectiles, something like a sphere shot forward.
I searched the forums but I didn’t find anything about it, can someone help me or point me to some docs or tutorials?

after some further research I found this Quickshot - 3 - Custom Projectile Tutorial:

I’ll try it as soon as I can.

Create your projectile BP and then add it to your vehicle BP as a child component.

Hi Jacky, thanks for the help. :slight_smile:

I added the Projectile BP as a child and created the logic following the tutorial, it works, but, there a thing that need to be addressed.

Projectiles are shot forward until the vehicle either is stopped or moves in a straight line. When the vehicle turns, projectiles kind of don’t follow the rotation of the vehicle in real time.

I recomend you to add an arrow component on the front of the vehicle, in the vehicle blueprint, and use the node “spawn actor from class” to spawn your projectile blueprint.

This way it will follow the rotation of your vehicle

A worst setup (but maybe needed in some cases) could be to get actor forward vector, and add it some forward distance to spawn the projectile on a imaginary point, generated each frame

Hi Nesjett, thanks for your help, I’m still learning.
I added the arrow and made graph:

The projectile doesn’t seem to behave correctly: in the image the car is turning, the projectile spawns at the location and rotation of the arrow but it should travel along the black line, instead it just seems to go along the tangent, I guess.

I think that the projectile spawns well, but you toke this screen some secs after the projectile spawned, so its normal that if the vehicle is moving it seems like what youre saying

Moreover, your drawed line is not very well calibrated, if you see it with detail, the location of the projectile is not much diferent than your “ideal” line, so I think that this confirm my first mentioned theory.

Just fire the projectile with the vehicle stoped, if it spawns well, move the vehicle to another location, stop it and fire another projectile, it should spawn good again

I took the shot just a spilt second after the projectile has been fired: I was using one hand to steer, accelerate and fire and the other to take the screenshot and I was trying to get a picture as clear as possible. :slight_smile:

The projectile spawns correctly and the graph works, there’s no doubt about it, It worked good with the setup by jacky too, both setups do just fine apparently and honestly I’m happy with that.
It is basically what I was trying to say in the 3rd post of this discussion, **** language barrier. :frowning:

The projectile behaves correctly, but, how can I make the projectile keep more centripetal force than it has now? I would like to make some testing about this.
Honestly I don’t know where to begin from.

Ah, I understand what you want to achieve, but right now I dont know how you should go about it.

Probably you should start looking on the projectile blueprint, and some way to make it react to lateral forces, maybe the velocity vector can help you with that

Or even sending a thresold from your vehicle BP to the Projectile BP and add this thresold to the projectile velocity vector

Ok, many thanks, I think lateral forces could be the right way to achieve this, I need to learn more about this.

Right now I’m trying to make the projectile system a little more complex: when a shot is fired a given amount of points (20) are drawn from the total (100), then it should start to “recharge” from new total (80) and get back to 100.
I’m trying to do this with a timeline but I can’t make it to start from where the shot is fired (80).
I tried with the SET PLAYBACK POSITION and SET NEW TIME nodes but apparently don’t work, I don’t understand what I’m doing wrong.

Timelines are not intended for this, because you need dynamic values

You have to make a function to restore x amount, and call it trought a timer

Today I kept working on it, I’m loggin in just now so I didn’t read your answer, and managed to get it working.
Basically I was setting a new time in the Timeline that was higher than its maximum value I didn’t get that with timelines you have input time values within the timeline length.
I feel so noob…

However the recharge system works just fine.
Is there a way to screen capture the whole BP 1:1 zoomed?
I tried to make sort of a mosaic with multiple screen captures but it is a nightmare.

I’m trying to make another type of projectile: what I have in mind is something which can be fired from the vehicle while it is running and that kind of follows the track until it collides with a target.

I made some experimenting, a BP with the following components: a static mesh, a spline and the logic to move the static mesh along the spline.
I added the BP as a child actor in the vehicle BP and spawned it using the Spawn Actor Node. The projectile spawns at the desired location but it behaves strangely: the mesh moves much slower than it should and the changes to the spline in the parent BP doesn’t affect the path of the projectile spawned in the vehicle BP.

In my understanding I need to get the spawning point of the projectile, spawn it, make it travel to the position of the nearest spline point and then make it to move along the spline from that point.

Now I’m wondering what could it be the right way to do it: should I use a projectile component and move it along the spline? Is it even possible?
Should I use a static mesh?
Should I use multiple BP, one for the spline, one for the projectile component and one for the vehicle?