12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- extends KinematicBody2D
- var player
- var motion = Vector2()
- export var speed = 150
- export var attackrange = 64
- export var reactiontime = 1
- var active = false
- export var detectionzone = 128
- export var exppt = 15
- func _ready():
- player = get_tree().get_nodes_in_group('player')[0]
- var array = []
- for x in $types.get_animation_list():
- array.append(x)
- array.shuffle()
- while array[0] == 'RESET':
- array.shuffle()
- $types.play(array[0])
- pass # Replace with function body.
- func _physics_process(delta):
- if player:
- for x in range(-1,1):
- for y in range(-1,1):
- if checkapproxpos(Vector2(x,y)):
- active = true
- if active:
-
- reactiontime -= 1
- if reactiontime == 0:
- motion = (player.global_position - global_position).normalized()
- reactiontime = 180
- $hitbox.position = motion * attackrange
- move_and_slide(motion * speed)
- $Sprite.rotation = atan2(motion.y * speed,motion.x * speed)
- func checkapproxpos(var offset = Vector2()):
- var pos1 = Vector2(int(player.global_position.x/detectionzone), int(player.global_position.y/detectionzone))
- var pos2 = Vector2(int(global_position.x/detectionzone), int(global_position.y/detectionzone))
- if pos1.y+offset.y == pos2.y+offset.y and pos1.x+offset.x == pos2.x+offset.x:
- return true
|