Search code examples
godottranslategodot4godot3

I need help "translating" this code from Godot 3 to Godot 4


I need to use this script written in godot 3 to work in godot 4

language is gdscript

extends Path2D

enum ANIMATION_TYPE {
    LOOP,
    BOUNCE,
}

export(ANIMATION_TYPE) var animation_type

onready var animationPlayer: = $AnimationPlayer

func _ready():
    match animation_type:
        ANIMATION_TYPE.LOOP: animationPlayer.play("MoveAlongPathLoop")
        ANIMATION_TYPE.BOUNCE: animationPlayer.play("MoveAlongPathBounce")

Solution

  • I tried it out and this way should work.

    extends Path2D
    
    enum ANIMATION_TYPE {
        LOOP,
        BOUNCE,
    }
    
    @export var animation_type : ANIMATION_TYPE
    
    @onready var animationPlayer: = $AnimationPlayer
    
    func _ready():
        match animation_type:
            ANIMATION_TYPE.LOOP: animationPlayer.play("MoveAlongPathLoop")
            ANIMATION_TYPE.BOUNCE: animationPlayer.play("MoveAlongPathBounce")