Attention | Topic was automatically imported from the old Question2Answer platform. | |
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);