Godot Version
4.6.2
Question
extends CharacterBody2D
const speed := 1000.0
const JUMP_VELOCITY := -1000.0
@export var player := 0 #Not a boolean because multiplayer is planned
@onready var camera_2d: Camera2D = $Camera2D
@onready var FrontLegCol: CollisionShape2D = $Abstract_mob/CollisionShape2D
#func _init() -> void:
#camera_2d.enabled = true
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
# Handle jump.
if player > 0 and Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Move
if player > 0:
var direction := Input.get_axis("left", "right")
if direction:
velocity.x = direction * speed
else:
velocity.x = move_toward(velocity.x, 0, speed)
if is_on_floor():
FrontLegCol.shape.y = 4
move_and_slide()