Как мне добавить перетаскивание к этому? - PullRequest
0 голосов
/ 10 марта 2020

Мне нужно добавить немного сопротивления мечу противника, чтобы игрок мог сражаться с противником, не получив травмы, когда они go атаковали его. Вот некоторый код:

extends Node2D
var Player_Position

func _physics_process(_delta):
    Player_Position = $Player.global_position
    $Ememy/KinematicBody2D/EnemySwordLeft.look_at(Player_Position)
    $Ememy/KinematicBody2D/EnemySwordRight.look_at(Player_Position)

Да, я в курсе, что написал противника неправильно.

Вот что я пробовал:

extends Node2D
var Player_Position

var timer = null #The timer
var EnemyDelay = 0.1 #the delay
var canFollow = true #checking if the arm can look at player

func _ready():
    #Making a timer for some delay
    timer = Timer.new() #Creating the timer
    timer.set_one_shot(true)
    timer.set_wait_time(EnemyDelay) #setting the wait time
    timer.connect("timeout", self, "onTimeoutComplete") #connecting the 
    #timer

    add_child(timer)

func onTimeoutComplete():
    canFollow = true #allowinf the sword to follow the player again

func _physics_process(_delta):
    if canFollow:
#making the sword follow the player
        Player_Position = $Player.global_position
        $Ememy/KinematicBody2D/EnemySwordLeft.look_at(Player_Position)
        $Ememy/KinematicBody2D/EnemySwordRight.look_at(Player_Position)
        #adding the delay
        canFollow = false
        timer.start()

этот код просто ставит его на паузу, затем меч просто привязывается к игроку, когда я попробовал это, он просто выглядел медленным, и на самом деле не добавлял никакой задержки, поскольку рука просто смотрела на игрока, когда таймер закончился.

...