I am trying to implement a shooting mechanic, I have created a machine gun and it shoots little projectiles really fast ect. The problem I am facing is that when the PlayerPawn and the Projectile collide head on, the PlayerPawn stops moving.
So I am trying to figure out the best way to implement this is. Right now I have them set to both block each other. Which understandably causes the PlayerPawn to be unable to walk forward while being shot form the front.
When I set either the PlayerPawn or the Projectile to ignore, nothing happens, the bullets go right through the PlayerPawn not dealing any damage.
What is the best way to implement shooting a projectile which collides with the character but allows the character to keep moving forward despite colliding with the projectile?
So with this solution instead of shooting a physical object you simply send out a trace that acts like a bullet and if it finds something it simulates a hit?
Yep, this is also what they used in the Shooter Example and I think it is common practice in the genre to use a LineTrace!
Getting the function to work may be a little tricky at the beginning (at least it was for me but I’m a total c++ noob) but if you don’t forget to draw debug lines, and exclude yourself from being hit by your own ray via parameters it will be fine!
You can also check out the function in blueprints, I’ve done it in both and its very easy in blueprints.
You could stick with your first solution, make the bullet not block anything and add a “damaging shape(e.g. a sphere)” around it that will trigger on overlap.
Then destroy on first overlap (or else you’ll have a railgun probably).
If you set the mass of the player to something large and the bullets to tiny then then bullets should take the change in momentum rather than the player.
Hey, it is possible I think. Set the collision groups of your pawn and your projectile to overlap each other (not block).
Make sure you have generate overlap events set to true.
Now you can react on overlaps in C++ code (maybe in blueprints, too I don’t know).
The player won’t be blocked, and you have your gravity bullet and you can “hit” the player.
What you also can do is to apply a force to damp the movement and not fully stop it when a player gets hit.
That did the trick! It only works if you set the “mass scaling” to anything < 1. With that value changed the character will be able to power through the collision. Thanks!
Yes UDK works slightly differently to Unity in terms of Physics & mass. In UDK you set the density (mass scaling) and it works out the mass from the collision volume. In Unity you set the mass directly. I guess UDK is slightly more fool proof because you are more likely to get correct mass, collect moment of inertia to get correct physics effects. A human should have a mass of around 100Kg & a bullet should have a mass of around .016Kg. You have to fiddle the mass scaling, which sets the mass, to achieve those masses but then you’ll get something a bit more realistic.
You can, in fact, do both those things with traces, which is generally the preferred method for fast moving, small projectiles. There’s two ways you could do it; one where you let the engine handle the simulation of the projectile’s motion and you handle the collision detection, and the other option is that you handle the motion of the projectile as well. Either way, essentially what you do is keep track of the projectile’s last position, and each tick you do a trace from the last position to the current position to see what it hit during it’s movement from last frame to this frame. You’re basically breaking up the arc of the projectile’s flight into a series of line segments, where each line segment is a raycast. The only problem is that traces (raycasts) do not account for projectile size (it’s an infinitesimally thin raycast), so if you’re projectile is large then it might be better to do a sphere-cast instead of a raycast.
I think this is a ‘must’ for projectiles that are realy fast. A faster projectile can jump over the target between two frames. Projectile with a 3000cm Velocity will travel about 100cms per frame in 30 fps. This means objects thinner then 100cm may never be get hit.