How to code smooth jumping/dashing instead of teleporting in the air?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Slyeet

So, I am making a 2dplatformer and when i jump or dash or walljump it just teleports me instead of going smoothly.

variables:

private int speed = 800;
 private float gravity = 20000;
 private float friction = 0.1f;
 private float acceleration = 0.25f;
 private float height = 20000;
 private float wallJump = 7000;
 private bool isDash = false;
 private int dashSpeed = 10000;
 private bool isDashAvailable = true;
 private float dashTimer = 0.2f;
 private float dashTimerReset = 0.2f;

jumping:

if (IsOnFloor()){
     if (Input.IsActionJustPressed("jump")) 
     {
         velocity.y = Mathf.Lerp(velocity.y,height,-0.4f);}
      isDashAvailable = true;
     }

dash:

 if(isDashAvailable)
 {
    if (Input.IsActionJustPressed("dash")){
        if ((Input.IsActionPressed("ui_left"))) 
        {
                velocity.x = -dashSpeed;
                isDash = true;
        }
        if ((Input.IsActionPressed("ui_right")))
        {
                velocity.x = dashSpeed;
                isDash = true;
        }
        if (Input.IsActionPressed("ui_up"))
        {
                velocity.y = -dashSpeed;
                isDash = true;
        }
        if ((Input.IsActionPressed("ui_left")) && (Input.IsActionPressed("ui_up"))) 
        {
                velocity.x = -dashSpeed;
                velocity.y = -dashSpeed;
                isDash = true;
        }
        if ((Input.IsActionPressed("ui_right")) && (Input.IsActionPressed("ui_up")))
        {
                velocity.x = dashSpeed;
                velocity.y = -dashSpeed;
                isDash = true;
        }
        isDashAvailable = false;
        dashTimer = dashTimerReset;
 }}

gravity

 if(isDash){
        dashTimer -= delta;
        if(dashTimer <=0){
            isDash = false;
            velocity = new Vector2(0,0);
        }
     }
     else{velocity.y += gravity*delta;}
      MoveAndSlide(velocity, Vector2.Up);
:bust_in_silhouette: Reply From: suribe

I don’t see any part in your code where you change the position of the objects. Is that in your MoveAndSlide function?

Anyway, you might want to take a look at the Tween object, which can do most of the work for you.
As an example, I’ve used it to move a camera from its current to a target position:

    var tween = GetTree().CreateTween();
    var timeInSeconds = 0.5f;
    tween.TweenProperty(this, "position", targetPosition, timeInSeconds)
		.SetEase(Tween.EaseType.InOut);

And that’s it. No need to worry about deltas, timers, or changing position manually.