Make a Character in Godot

Published on December 15, 2025

Code Snippets

clown_nose.gd

extends CharacterBody2D
class_name ClownNose


const GRAVITY := 690.0


@export var move_speed := 180.0
@export var jump_height := 300


@onready var animated_sprite_2d = $AnimatedSprite2D

func _process(_delta):
  get_input()


func _physics_process(delta):
  if not is_on_floor():
    # fall
    velocity.y += GRAVITY * delta
  
  move_and_slide()


func get_input():
  var axis_value = Input.get_axis('left', 'right')
  var move_direction = sign(axis_value) if axis_value != 0 else 0
  
  velocity.x = axis_value * move_speed
  if move_direction != 0:
    animated_sprite_2d.flip_h = move_direction < 0
  
  if Input.is_action_just_pressed('jump'):
  velocity.y = -jump_height