How do you spawn a projectile actor and launch it from the gun’s muzzle location(get socket transform) - gun is a mesh, and with a rotation from the gun’s muzzle location to a line traces hit destination?
And should I make the projectile slow enough to be visible or just use it for the purpose of proper delay before hit effects? Please answer this regarding your personal opinions.
Where I expose this->ProjectileClass as a BluePrint variable and choose a BluePrint class which has AProjectile as a parent class.
Regarding the speed of projectile, I do not slow it down to be visible, but I am planning to attach a particle effect to it.
If you want a gun with bullets that the player can see (e.g. Star Wars), then you want a projectile actor.
Spawn it with GetWorld()->SpawnActor<your_projectile_actor>(). Then just set its location to the right spot and set its velocity to make it go where you want it to go.
If you want a gun that works more like real life, then you don’t need a projectile actor.
You can use GetWorld()->LineTraceSingleByChannel() to trace a line from the gun and see what it hits.
In either case, you’ll need to set up collision channels or you won’t know what you actually hit. If you go with the projectile method, you also need to setup the OnHit for the actor to do something when it hits the target.
The projectile method is quite a bit more expensive… spawning an actor, moving each tick, testing for collision, destroying the actor on impact, and so on…
Either way, it’s kind of a hassle to get it all setup, but straightforward if you look at the examples.