Godot Version
godot-4
Question
Hi, i have to create a game for my school project and i am trying to make my player have different speed and jump height per different level but i dont know how?
extends CharacterBody2D
@onready var player: CharacterBody2D = $"."
const SPEED = 150.0
const JUMP_VELOCITY = -250.0
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D
func _physics_process(delta: float) -> void:
# Gravitation
if not is_on_floor():
velocity += get_gravity() * delta
# Springen
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
#Richtungs eingaben
var direction := Input.get_axis("move_left", "move_right")
#Sprite drehen
if direction > 0:
animated_sprite.flip_h = false #Horizontal drehen
elif direction < 0:
animated_sprite.flip_h = true
#animationen
if is_on_floor():
if direction == 0:
animated_sprite.play("Idle")
else:
animated_sprite.play("sprint")
else:
animated_sprite.play("jump")
#Bewegung Hinzufuegen
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()