Created
January 17, 2020 00:15
-
-
Save ealbinu/f92f4f423c78f4bab34216b2e9976b56 to your computer and use it in GitHub Desktop.
Godot: Enemigo camina hacia la dirección del player
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends KinematicBody2D | |
# Velocidad a la que se acerca el enemigo | |
var velocidad = 150 | |
# Distancia entre el enemigo y el player | |
var distancia = 250 | |
var movcont = 0 | |
# Ruta hacia el PLAYER | |
onready var player = get_parent().get_parent().get_node("PLAYER-KinematicBody2D") | |
func _physics_process(delta): | |
var dist = player.global_position.distance_to(global_position) | |
var dir = player.global_position.x - global_position.x | |
if dist<distancia: | |
if movcont == 0: | |
movcont = dir | |
move_and_collide(Vector2(movcont, 0).normalized() * velocidad * delta) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment