Creating a dodge/dash in player movement script

I’m having trouble creating a dash script for my player. I wanted players to be able to dodge through damage, so I directly moved the character’s location on dash, but that has the effect of popping you into obstacles. Instead, I figured I could just “change” the player state and use smoothdamp to move the player. I’ve used it on my camera movement, so I implemented it the same way, but nothing happens.

Vector3 dodgeVel = Vector3.zero;
float dodgeDistance = 5;
float dodgeDuration = 0.125f;

if (playerInput.x > 0 && Input.GetKeyDown(KeyCode.RightShift) {
      transform.localPosition = Vector3.SmoothDamp(
                transform.localPosition,
                (transform.localPosition + (Vector3.right * dodgeDistance)),
                ref dodgeVel,
                dodgeDuration
      );
      playerDodge(1); // calls a particle effect
}

I know the script is being called, because the particle effect shows up, but the player doesn’t move at all. Is there a better way to do this, or did I just implement SmoothDamp incorrectly?

EDIT:
So, it turns out that the Dodge is working, but it’s hard to tell because it’s too slow/not far enough, so the character’s movement seems to cancel it out to some extent. It also still teleports through walls, so I need a better implementation.

What is keeping you out of obstacles? If it is physics, then you should NEVER use the transform directly to set position.

When using physics, always use the .MovePosition() method on the Rigidbody (or Rigidbody2D). With physics, using transform.position / .localPosition bypasses the physics engine leading to bad things.

That makes sense. Thanks for the suggestion! I’ll try that and see if it works better