Godot Version
4.5.1 stable
Question
So I have been trying to make this automation game thats 2d and I want the camera to follow player but when I do that the player freezes and cant move.
this is my code for player (the project is new and Im a beginner)
extends CharacterBody2D
#region Variables
@onready var pickaxe = $Pickaxe
@onready var player = $AnimatedSprite2D
const SPEED = 60.0
const JUMP_VELOCITY = -200.0
const floatiness = 0.8
#endregion
#region Functions
func _pickaxe():
if Input.is_action_pressed("Piackaxe"):
pickaxe.show()
else:
pickaxe.hide()
func _gravity(delta):
if not is_on_floor():
velocity += get_gravity() * delta * floatiness
func _handleMovement():
var direction := Input.get_axis("left", "right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
func _handleJump():
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
func _handlePlayerAnimation():
if velocity.x != 0:
player.play("Run")
else:
player.play("Idle")
func _Handleflip():
var direction := Input.get_axis("left", "right")
if direction > 0:
player.flip_h = direction < 0
pickaxe.scale.x = 5
pickaxe.position.x = abs(pickaxe.position.x)
elif direction < 0:
player.flip_h = true
pickaxe.scale.x = -5
pickaxe.position.x = -abs(pickaxe.position.x)
#endregion
#region calling functions
func _physics_process(delta: float) -> void:
_gravity(delta)
_handleJump()
_handleMovement()
_Handleflip()
_handlePlayerAnimation()
_pickaxe()
move_and_slide()
#endregion