NPC Projectiles

I’m trying to get an NPC to spawn and shoot arrows. It does so, but on detaching from the actor, the projectile goes in the wrong direction. There’s probably some math that’s incorrect.

Does it go in a random direction or opposite?

Not random but not exactly the opposite, more like to the side and down. I did a somewhat fix by setting the velocity of the projectile to a value on the y axis after the detach, which sends it going in the right direction more or less, but I don’t think this is the correct fix.

Probably the easiest fix would be to have one arrow that is attached and when you fire, it swaps to another arrow that is a projectile and goes forward. Then you can take the direction of players camera and use that to determine the exact direction of the arrow.

Also I noticed that you have cast to on tick, which is pretty expensive. You should do one cast to on begin play and save that anim instance as a variable and use that instead of casting every tick.

1 Like

The tick is temporary :slight_smile: using it to test the animation timing. BP is going to be called in the sequencer anyway with a custom event. I definitely think its the velocity since changing the value changed the direction. It’s an NPC, so I need the arrow to follow the direction of the hand of the character, so maybe the velocity needs to be set to some value surrounding that particular socket?

Are you using projectile component on the arrow or are you adding force by yourself?

projectile component

Ok, then you should be able to just set the direction to be the same as where you are aiming(probably take the forward vector from the camera). I would probably spawn a new arrow in the same place the moment the arrow should start flying and if the settings are set up correctly in the arrow projectile, it should work fine.

why do you detach it?

You just spawn in proper direction and location, the rest is going from Projectile Movement to force it to ‘fly’ somewhere

1 Like

I had to detach it, because I originally attached it on spawn-- it spawned before it shoots because the character is reaching/ fitting it to the bow during the animation–

So I pretty much just changed it all. I set up notify on the animation itself, and called it in the anim blueprint to activate the projectile at said notify. Then I changed the projectile to a homing projectile and set a target for it to home to within the projectile BP via a component tag–skipping most of the math-- I think the character’s hand just moves too much. I skipped the attach/detach altogether and simply parented a static mesh to the socket of the hand withing the BP, turning on and off the visibility via notifies in the animation as well.

After you detach and it’s using its regular velocity again, you can use Suggest Projectile Velocity, Granted I DO NOT do this on a homing projectile. just feed the end location as where you want your enemy to shoot at IE Player or object whatever its target is. Basically its a (You tell me where it is and I’ll travel there.) Keep in mind this will shoot the projectile at the location it was given when shot, but if the player moves after, it will miss. So, basically like an arrow. Definitely DO NOT attach the Suggest Projectile Velocity on a Tick event Just so we are clear.


I see, I can understand your point but for Projectiles Attaching and Detaching isn’t what you want :wink: (@OORTIZ also gave a nice explanation)

You can simply disable simulation by default so it will stay in place and run the simulation when you’re ready

For now (as I am outside my home) I don’t know if and what should be a good way to keep the location ‘attached’ to something but instead you can add a component representing your Projectile and when you want to finally shoot - spawn your Projectile and immediately after - destroy the component that’s just playing the visual role in your System :slight_smile:

1 Like

It’s ok, I don’t need the functionality of the character, it’s literally a background character that you don’t interact with at all–and the shooting loops a few times on the animation. So the shots need to pretty much be the same-- when just disabling and enabling the simulation initially, there was too much deviation in the shots due to too much movement in the hands. Making it a homing projectile works for this particular instance and turning on/off the visibility of the static mesh of the arrow before and after the shot. I did end up spawning the projectile right after anyway but in a more stable spot. I know it’s not the typical way, but it works for what I need it to do. It’s good to know the above info though if I do something else that requires more functionality :slight_smile: