Advertisement
Dieton

player_debug.gd

Sep 30th, 2024
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 1.68 KB | Gaming | 0 0
  1. extends CharacterBody3D
  2.  
  3. @export var movement_speed = 5.0
  4. @export var jump_strength = 10.0
  5. @export var gravity = 9.8
  6.  
  7. @onready var debug_console = get_tree().root.get_node("DebugConsole")  # Adjust the path as needed
  8.  
  9. func _ready():
  10.     # Check for the debug console in the scene
  11.     if debug_console:
  12.         debug_console.log_message("Player is ready.")
  13.  
  14. func _process(delta):
  15.     # Example of sending debug information
  16.     if debug_console:
  17.         debug_console.log_message("Player position: " + str(global_position))
  18.  
  19. func _physics_process(delta):
  20.     handle_movement(delta)
  21.  
  22. func handle_movement(delta):
  23.     var input_velocity = Vector3.ZERO  # Use a separate variable for input
  24.  
  25.     # Basic movement logic
  26.     if Input.is_action_pressed("move_forward"):  # Ensure this action is defined in Input Map
  27.         input_velocity.z -= 1
  28.     if Input.is_action_pressed("move_backward"):
  29.         input_velocity.z += 1
  30.     if Input.is_action_pressed("move_left"):
  31.         input_velocity.x -= 1
  32.     if Input.is_action_pressed("move_right"):
  33.         input_velocity.x += 1
  34.  
  35.     input_velocity = input_velocity.normalized() * movement_speed
  36.  
  37.     # Apply gravity
  38.     if not is_on_floor():
  39.         input_velocity.y -= gravity * delta
  40.  
  41.     # Set the character's velocity based on the input and gravity
  42.     velocity = input_velocity
  43.  
  44.     # Move the player with the calculated velocity
  45.     move_and_slide()  # No arguments needed for CharacterBody3D
  46.  
  47.     # Example of sending debug info
  48.     if debug_console:
  49.         log_to_console("Player position: " + str(global_position))
  50.  
  51. func log_to_console(message: String):
  52.     # Send debug information to the debug console
  53.     if debug_console and debug_console.has_method("log_message"):
  54.         debug_console.log_message(message)  # Use log_message directly
  55.  
Tags: Godot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement