I am making a simple platformer to understand Godot better and I am trying to make a simple dash function (left and right) and I don't want to fall while dashing (I want to go perfectly horizontal during the dash) I am using GDscript and my setup is
---
---
Here is my code as of now:
extends KinematicBody2D
export (int) var speed = 250 #walking speed
export (int) var jump_speed = -600 #the power of the jump
export (int) var gravity = 700 #the downwards force on the player
export (int) var max_fall_speed = 540 #the maximum speed the player can fall
export (int) var ground_pound_speed = 300 #how fast the player ground pounds
export (int) var dash_distance = 4000 #how far the dash takes the player
var direction
var velocity = Vector2.ZERO
func get_input():
velocity.x = 0
if Input.is_action_pressed("walk_right"):
velocity.x += speed
direction = 2 #right is equal to 2
if Input.is_action_pressed("walk_left"):
velocity.x -= speed
direction = 1 #left is equal to 1
if Input.is_action_just_pressed("dash"):
if direction == 1:
velocity.x -= dash_distance
if direction == 2:
velocity.x += dash_distance
func _physics_process(delta):
get_input()
velocity.y += gravity * delta
velocity = move_and_slide(velocity, Vector2.UP)
if Input.is_action_pressed("jump"):
if is_on_floor():
velocity.y = jump_speed
if Input.is_action_just_pressed("down"):
velocity.y = ground_pound_speed
func _process(delta):
velocity.y = move_toward(velocity.y, max_fall_speed, gravity * delta)