Godot Version
Replace this line with your Godot version
Question
Ask your question here! Try to give as many details as possible.
If you share code, please wrap it inside three backticks or replace the code in the next block:
extends CharacterBody2D
class_name PlayerController
@export var speed = 10.0
@export var jump_power = 10.0
var speed_multiplier = 30.0
var jump_multiplier = -30.0
var direction = 0
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _Input(event):
if event.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_power * jump_multiplier
if event.is.action_pressed("move down"):
set_collision_mask_value(10, false)
else:
set_collision_layer_value(10, true)
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
direction = Input.get_axis("move left", "move right")
if direction:velocity.x = direction * speed * speed_multiplier
else:
velocity.x = move_toward(velocity.x, 0, speed * speed_multiplier)
move_and_slide()
