Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody3D
- @export var movement_speed = 5.0
- @export var jump_strength = 10.0
- @export var gravity = 9.8
- @onready var debug_console = get_tree().root.get_node("DebugConsole") # Adjust the path as needed
- func _ready():
- # Check for the debug console in the scene
- if debug_console:
- debug_console.log_message("Player is ready.")
- func _process(delta):
- # Example of sending debug information
- if debug_console:
- debug_console.log_message("Player position: " + str(global_position))
- func _physics_process(delta):
- handle_movement(delta)
- func handle_movement(delta):
- var input_velocity = Vector3.ZERO # Use a separate variable for input
- # Basic movement logic
- if Input.is_action_pressed("move_forward"): # Ensure this action is defined in Input Map
- input_velocity.z -= 1
- if Input.is_action_pressed("move_backward"):
- input_velocity.z += 1
- if Input.is_action_pressed("move_left"):
- input_velocity.x -= 1
- if Input.is_action_pressed("move_right"):
- input_velocity.x += 1
- input_velocity = input_velocity.normalized() * movement_speed
- # Apply gravity
- if not is_on_floor():
- input_velocity.y -= gravity * delta
- # Set the character's velocity based on the input and gravity
- velocity = input_velocity
- # Move the player with the calculated velocity
- move_and_slide() # No arguments needed for CharacterBody3D
- # Example of sending debug info
- if debug_console:
- log_to_console("Player position: " + str(global_position))
- func log_to_console(message: String):
- # Send debug information to the debug console
- if debug_console and debug_console.has_method("log_message"):
- debug_console.log_message(message) # Use log_message directly
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement