Snippets Collections
extends CharacterBody2D
 
@export var SPEED : int = 150
@export var JUMP_FORCE : int = 255
@export var GRAVITY : int = 900
 
func _physics_process(delta):
	
	
	var direction = Input.get_axis("Left","Right")
	
	if direction:
		
		velocity.x = SPEED * direction
		
		if is_on_floor():
			
			$AnimatedSprite2D.play("Run")
		
	else:
		
		velocity.x = 0
		
		if is_on_floor():
			
			$AnimatedSprite2D.play("Idle")
	
	# Rotate
	
	if direction == 1:
		$AnimatedSprite2D.flip_h = false
	elif direction == -1:
		$AnimatedSprite2D.flip_h = true
		
	
	# Gravity
	
	if not is_on_floor():
		
		velocity.y += GRAVITY * delta
		
		if velocity.y > 0:
			
			$AnimatedSprite2D.play("Fall")
	
	# Jump
	
	if is_on_floor():
		
		if Input.is_action_just_pressed("Jump"):
			
			velocity.y -= JUMP_FORCE
			$AnimatedSprite2D.play("Jump")
	
	
	move_and_slide()
 
extends KinematicBody2D

var velocity = Vector2(0,0)
export var speed : int = 180
export var jumpForce : int = 850
export var gravity : int = 35


func _physics_process(delta):
	if Input.is_action_pressed("right"):
		velocity.x = speed
		$Sprite.play("walk")
		$Sprite.flip_h = false
	elif Input.is_action_pressed("left"):
		velocity.x = -speed
		$Sprite.play("walk")
		$Sprite.flip_h = true
	else:
		$Sprite.play("idle")
	
	if not is_on_floor():
		$Sprite.play("air")
		
		
	
	velocity.y += gravity
		
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = -jumpForce
	
		
	velocity = move_and_slide(velocity,Vector2.UP)
	velocity.x = lerp(velocity.x, 0, 0.3)	
extends KinematicBody2D

var velocity = Vector2(0,0)
export var speed : int = 180
export var jumpForce : int = 850
export var gravity : int = 35


func _physics_process(delta):
	if Input.is_action_pressed("right"):
		velocity.x = speed
	if Input.is_action_pressed("left"):
		velocity.x = -speed
		
	
	velocity.y += gravity
		
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = -jumpForce
		
	velocity = move_and_slide(velocity,Vector2.UP)
	velocity.x = lerp(velocity.x, 0, 0.3)	
star

Wed Jan 10 2024 05:31:30 GMT+0000 (Coordinated Universal Time) https://www.thiscodeworks.com/player-code/657df2007373ec00142ea2bd

#gdscript
star

Mon Mar 14 2022 23:08:16 GMT+0000 (Coordinated Universal Time) https://www.youtube.com/watch?v=oAb_Ju33fqU

#gdscript #godot
star

Mon Mar 14 2022 11:33:58 GMT+0000 (Coordinated Universal Time) https://www.youtube.com/watch?v=oAb_Ju33fqU

#gdscript #godot

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension