FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál
  • ✇Recent Questions - Game Development Stack Exchange
  • How can I perform hot reload in Godot?shingo.nakanishi
    In the documentation for versions 3.5 and 4.3, it mentions that hot reloading is possible: 3.5: https://docs.godotengine.org/en/3.5/getting_started/introduction/godot_design_philosophy.html 4.3: https://docs.godotengine.org/en/4.3/getting_started/introduction/godot_design_philosophy.html Godot tries to provide its own tools to answer most common needs. It has a dedicated scripting workspace, an animation editor, a tilemap editor, a shader editor, a debugger, a profiler, the ability to hot-reloa
     

How can I perform hot reload in Godot?

In the documentation for versions 3.5 and 4.3, it mentions that hot reloading is possible:

3.5: https://docs.godotengine.org/en/3.5/getting_started/introduction/godot_design_philosophy.html

4.3: https://docs.godotengine.org/en/4.3/getting_started/introduction/godot_design_philosophy.html

Godot tries to provide its own tools to answer most common needs. It has a dedicated scripting workspace, an animation editor, a tilemap editor, a shader editor, a debugger, a profiler, the ability to hot-reload locally and on remote devices, etc.

The Godot editor runs on the game engine. It uses the engine's own UI system, it can hot-reload code and scenes when you test your projects, or run game code in the editor. This means you can use the same code and scenes for your games, or build plugins and extend the editor.

But how exactly do you perform it?

For example, in Flutter, if you type r or shift + r in the terminal after running $ flutter run, it performs a hot reload. How do you do something similar in Godot? Does simply saving a GDScript file trigger hot reload? (It doesn't seem to work that way for me...)

(More specifically, in Flutter, r is hot reload and shift + r is hot restart.)

I am editing GDScript using either VSCode or the editor included with Godot, and I am running it using the play button(attached below) in Godot.


Since this is a large project, providing a minimal code example might be time-consuming or even impossible. Could you simply explain the steps for performing a hot reload? Is it possible to do this using only the inspector? Is it not possible to directly modify the GDScript file for this? Also, is the hot reload triggered automatically, or do I need to press a button to initiate it?

If I can understand the correct patterns and limitations for performing hot reloads accurately, I think I’ll be able to experiment on my own. (Or, I can give up on the patterns that don’t work.)

enter image description here

  • ✇Recent Questions - Game Development Stack Exchange
  • Godot on signal trigger external animationdepperm
    It may not matter, but I'm following How to make a Video Game - Godot Beginner Tutorial. I want to implement the dying animation instead of removing CollisionShape2D from the body (parameter passed to Area2D's _on_body_entered signal). The player: The player animations: The code to remove the CollisionShape2D (player falls off the screen before restarting, based on tutorial) that works: func _on_body_entered(body): print("You die") Engine.time_scale = 0.5 body.get_node("CollisionSh
     

Godot on signal trigger external animation

It may not matter, but I'm following How to make a Video Game - Godot Beginner Tutorial. I want to implement the dying animation instead of removing CollisionShape2D from the body (parameter passed to Area2D's _on_body_entered signal).

The player:

enter image description here

The player animations:

enter image description here

The code to remove the CollisionShape2D (player falls off the screen before restarting, based on tutorial) that works:

func _on_body_entered(body):
    print("You die")
    Engine.time_scale = 0.5
    body.get_node("CollisionShape2D").queue_free()
    timer.start()

What I've tried to get dying animation to play:

func _on_body_entered(body):
    print("You die")
    var player_anim = body.get_node("AnimatedSprite2D") # tried a single line as well
    Engine.time_scale = 0.5
    player_anim.play("dying" )
    timer.start()

I get no errors, it just resets after the designated amount of time. Is it possible to trigger player dying animation from Area2D script?

  • ✇Recent Questions - Game Development Stack Exchange
  • Movement continues for diagonal movement after releasing one keyJChips
    For example, if I press W key and D key, that would produce a movement in the Northeast position. However, if I release either key (meaning I am holding only W or D at the moment), the movement still continues going northeast when I want it to go east if it is D only, and north if it is W only. However, if I release both of the keys and then press either W or D it works perfectly. The code for my main CharacterBody2D: extends CharacterBody2D class_name Player var x_input: float = 0.0 var y_inpu
     

Movement continues for diagonal movement after releasing one key

For example, if I press W key and D key, that would produce a movement in the Northeast position. However, if I release either key (meaning I am holding only W or D at the moment), the movement still continues going northeast when I want it to go east if it is D only, and north if it is W only. However, if I release both of the keys and then press either W or D it works perfectly.

The code for my main CharacterBody2D:

extends CharacterBody2D
class_name Player

var x_input: float = 0.0
var y_input: float = 0.0
var pause_lock: bool = false

@onready var sprite = $PlayerSprite
@onready var f_arm = $PlayerSprite/Torso/R_Arm
@onready var b_arm = $PlayerSprite/Torso/L_Arm
@onready var hand = $PlayerSprite/Torso/R_Arm/Hand
@onready var aim_pivot = $PlayerSprite/Torso/AimPivot
@onready var fsm = $FSM
@onready var leg_anim = $LegsAnimation

@export var MAX_SPEED       : int = 50
@export var ACCELERATION    : int = 1000
@export var FRICTION        : float = 1.0

@export var base_hp         : int = 0
@onready var hp: int = base_hp

var motion : Vector2 = Vector2.ZERO
var direction : Vector2 = Vector2.ZERO

func _player_input():
    x_input = Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
    y_input = Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
    
    direction = Vector2(x_input, y_input).normalized()

func _idle():
    motion.x = lerp(motion.x, 0.0, FRICTION)
    motion.y = lerp(motion.y, 0.0, FRICTION)

func _move(delta, direction):
    motion += direction * ACCELERATION * delta
    motion.x = clamp(motion.x, -MAX_SPEED, MAX_SPEED)
    motion.y = clamp(motion.y, -MAX_SPEED, MAX_SPEED)
    
    print(motion)
    velocity = motion
    move_and_slide()

func aim(pos: Vector2):
    _flip_player_sprite(pos.x < self.global_position.x)
    if (pos.x < self.global_position.x):
        f_arm.rotation = lerp_angle(f_arm.rotation, -(aim_pivot.global_position - pos).angle(), (0.10))
    else:
        f_arm.rotation = lerp_angle(f_arm.rotation, (pos - aim_pivot.global_position).angle(), (0.10))
    b_arm.look_at(hand.global_position)

func _flip_player_sprite(flip: bool):
    match flip:
        true:
            sprite.scale.x = -1
        false:
            sprite.scale.x = 1

func _animate_legs():
    if (direction == Vector2.ZERO):
        leg_anim.play("Idle")
    else:
        var is_forward: bool = (
                (sprite.scale.x == 1)
                or (sprite.scale == Vector2(-1,1) and x_input < 0)
        )
        
        match is_forward:
            true:
                leg_anim.play("Walk_Forward")
            false:
                leg_anim.play("Walk_Backward")

The code for the finite state machine attached as a child:

extends Node

enum STATES {IDLE, MOVE}

var state: int = 0

@onready var parent = get_parent()


func _physics_process(delta):
    run_state(delta)


func run_state(delta):
    parent._player_input()
    parent.aim(parent.get_global_mouse_position())
    
    match state:
        STATES.IDLE:
            parent._idle()
            
            if (parent.direction != Vector2.ZERO):
                _set_state(STATES.MOVE)
        STATES.MOVE:
            parent._animate_legs()
            parent._move(delta, parent.direction)
            
            if (parent.direction == Vector2.ZERO):
                _set_state(STATES.IDLE)


func _set_state(new_state: int):
    if (state == new_state):
        return
    
    state = new_state
❌
❌