So I have recently converted one of my characters into a much simpler pawn, the previous character had was using the LaunchCharacter functionality which I was using to implement a simple knockback and now my pawn does not have access to this.
I have tried everything from applying force, adding movement input to my new pawn but I just cannot get the pawn to get knocked back
Any help would be appreciated, here is my “previous” code:
You can see above I get the movement vector between and pusher and the pushed and multiplying it by a negative amount. This value was passed into launch character and worked as expected. So I think I have half the puzzle here to launch the pawn.
If you are replacing the Character, you’ll need to also replace the CharacterMovementComponent with some other physics simulation.
This means that you are responsible for the simulation!
There are two ways to go about this:
Set position/velocity directly using whatever mechanism you want
Use a physics body (such as a sphere, capsule, or box) and drive it with forces and torques
If you are using option 1, then set the velocity to whatever you want when knocking it. How that simulation really works, is up to you.
If you are using option 2, then use AddImpulse() to add a force impulse to the body. You may need to add a quite high impulse value, because unreal units are small. The slowdown while in the air can be implemented for example with the linear damping/drag coefficient on the body.
I want to avoid Enabling Physics on this pawn because it seems to effect the pawns collision in regards to other actors. so i think option 2 may be out for me.
For option 1, my pawn has a UBoxComponent and a default static mesh, these components do not seem to have velocity parts that I can manipulate. I have looked into floating pawn movement component but that does not seem correct.
I have set actors position but it of course teleports the pawn rather than “moving it”
If you insist on doing everything manually, then you have to implement “Velocity” yourself.
Add a vector called “Velocity,” and update the position in Tick. A typical update look might look something like:
In general, gameplay character/player dynamics is a full time job for a game programmer, because the “feel” of a character is super important. There are likely years of total work going into the character controller and simulator in the Character class. (To make it “stick to the floor” and “work well on a network” and “collide properly with things” and “not tunnel through walls” and “have good control feel” and so on.)
I’m not saying you shouldn’t implement your own – sometimes, that’s absolutely the right chocie – I’m just validating your observation that there’s a lot of different things to think about and implement.
Thank you for your observation, I have implemented physics and fine tuned some of my collisions to work with physics enabled and managed to get the knockback working as intended, so thank you for your help.
Code for anyone in the future (Enable the pawn being knocked back to have phyics enable = true):