I’m wanting to add a kick first person shooter and would like the kick to apply force based on my characters velocity relative to the target weight versus their weight.
so in other words if I’m Going extremely fast I want my kick to hit like a semi truck.
if I kick a small enemy I want to punt it like a football.
if I kick a large enemy I want that enemy to barely move, but knock back the player.
also, I would like that kick to be able to allow players to jump off of walls.
Any suggestions on how to Do that without having to do extremely meticulous calculations?
Just use addforce to rigidbodies and make sure the big enemies have a bigger mass
Then you just need to add the velocity of the player with maybe a multiplier
// pseudo code...
// play with different values in the inspector...
[SerializeField] float kickStrength = 2f;
[SerializeField] float kickRadius = 4f;
[SerializeField] float kickUpliftingPower = 3f; // the bigger, the more the enemy will go higher...
var velocity = player.rigidbody.velocity;
var kickPower = velocity.magnitude * kickStrength; // the faster the player, the stronger the kick...
// get your enemyt rigidbody, maybe from collision.rigidbody?
enemyRigidbody.AddExplosionForce(kickPower, enemyRigidbody.position, kickRadius, kickUpliftingPower);
Definitely what Nad_B and DevDunk suggest… don’t try and let the physics figure it out, because if there are large mass disparities and huge speeds, you will be launching stuff into orbit.
Instead, do your own calculations (like Nad_B suggests above) and then figure out what you want.
Figure out and define for your computations a minimum amount of kick per enemy to make it noticeable, and a maximum amount to make him not hit the International Space Station.
You could also compare the height of the enemy to you: if it is a little low enemy, impart an upwards component too, to make it comically pop up like a football. Otherwise an equivalent or large size enemy would push directly back, not upwards.
Well, that’s the thing. I absolutely do want to kick enemies into orbit. Like I mentioned before my character is going to be able to go about half the speed of sound in the right circumstances.