0 votes

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);
Godot version 3.5.1
in Engine by (12 points)

1 Answer

0 votes

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.

by (37 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.