![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Arun33 |
Problem with move_and _slide function
extends CharacterBody2D
var velocity : Vector2
@export var speed : int = 1000
@export var gravity: float = 55
@export var jump_force : int = 1600
func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity
if velocity.y >2000:
velocity.y = 2000
if Input.is_action_just_pressed("ui_right"):
velocity.x = speed
$Sprite.flip_h = false
elif Input.is_action_just_pressed("ui_left"):
velocity.x = -speed
$Sprite.flip_h = true
else:
velocity.x = 0
if Input.is_action_just_pressed("ui_select"):
if is_on_floor():
velvelociy.y = -jump_force
velocity = move_and_slide (velocity, Vector2.UP)