协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
gdscript【开发与工程】Write, debug, and optimize GDScript code for Godot Engine 4.x. Use this skill when creating scripts, fixing GDScript errors, connecting signals, configuring export variables, setting up node references, or implementing character movement and game logic in GDScript.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
extends Node2D # or Node3D, CharacterBody2D, etc.
# Export variables for editor inspection
@export var speed: float = 200.0
@export var health: int = 100
# Node references
@onready var sprite = $Sprite2D
@onready var animation_player = $AnimationPlayer
# Signals
signal health_changed(new_health)
signal died()
# Private variables
var _velocity: Vector2 = Vector2.ZERO
var _is_alive: bool = true
func _ready():
# Initialize when node enters scene tree
pass
func _process(delta: float):
# Called every frame
pass
func _physics_process(delta: float):
# Called every physics frame (fixed timestep)
pass
# Define signal
signal player_hit(damage: int)
# Connect in code
enemy.player_hit.connect(_on_player_hit)
# Connect in editor (via @export)
func _on_player_hit(damage: int):
health -= damage
health_changed.emit(health)
extends CharacterBody2D
@export var speed: float = 200.0
@export var jump_velocity: float = -400.0
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_velocity
var direction = Input.get_axis("move_left", "move_right")
velocity.x = direction * speed
move_and_slide()
extends CharacterBody3D
@export var speed: float = 5.0
@export var jump_velocity: float = 4.5
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
func _physics_process(delta):
if not is_on_floor():
velocity.y -= gravity * delta
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = jump_velocity
var input_dir = Input.get_vector("move_left", "move_right", "move_forward", "move_back")
var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
if direction:
velocity.x = direction.x * speed
velocity.z = direction.z * speed
else:
velocity.x = move_toward(velocity.x, 0, speed)
velocity.z = move_toward(velocity.z, 0, speed)
move_and_slide()
@onready for node references (resolved when scene enters tree)@export for editor-configurable valuesmove_and_slide() for character physics_physics_process() for physics calculations_process() for visual/gameplay updatesprint() or prints() for console outputbreakpoint keyword or push_warning() for debugging