Greetings everyone!
I’ve been struggling with this for the past couple days, watched lots of related videos, topics and solutions.
But I still can’t figure out how to make a rigidbody controller that both has a snappy movement and support for external forces like Pushbacks, explosion forces, impulses, moving platforms… etc.
The problem I’m facing is as follow:
here’s the code I use for movement.
protected void HandleMovement()
{
Vector2 input = ReadInput();
Vector3 moveDirection = GetMoveDirectionNormalized(input);
Vector3 horizontalVelocity = GetHorizontalVelocity();
rb.AddForce(moveDirection * GetSpeed() - horizontalVelocity, ForceMode.VelocityChange);
}
this code runs in my state machine in all states in fixed update.
the reason I’m using VelocityChange and subtracting horizontal velocity is because I want the player to have snappy movement and not accelerate.
but due to this code, any impulses or external forces applied to the player runs for only 1 frame the gets removed.
I can’t figure away to solve this.
I don’t want a complete physics based movement where the player builds up speed and momentum, but rather just normal movement with the ability to apply forces on the player, and have the player either fight back against these forces by going on the opposite direction or go alongside it or just do nothing and let the force do it’s thing.
something similar to super smash bros or multiversus where when a player gets pushed he can still fight against that push by moving in opposite direction, or maybe the same effect of an impulse grenade in fortnite
or like having a gravity well that sucks players in but at the same time the player has a chance of running out of it if he keeps moving
or like in overwatch where there are abilities that pushes other players but at the same time doesn’t disable their ability to move.
I know it’s gotta be something simple in the end, but everything I tried just isn’t working as exptected.
so this place is probably my last hope ;-;