the-crypt/ai/SpinningBone.gd

25 lines
575 B
GDScript3
Raw Normal View History

2020-07-20 14:14:34 -05:00
extends KinematicBody2D
var velocity = Vector2.ZERO
var speed = 100
func _physics_process(delta):
var c = move_and_collide(velocity)
if c != null:
on_impact(c)
2020-07-18 17:07:40 -05:00
func launch_right():
velocity = (Vector2.RIGHT * speed)
func launch_left():
velocity = (Vector2.LEFT * speed)
func launch_upleft():
velocity = (Vector2(-1, -1).normalized() * speed)
func launch_upright():
velocity = (Vector2(1, -1).normalized() * speed)
2020-07-20 14:14:34 -05:00
2020-07-18 17:07:40 -05:00
func on_impact(collision):
2020-07-20 14:14:34 -05:00
print(collision.collider)
2020-07-18 17:07:40 -05:00
if collision.collider.has_method("get_type"):
2020-07-20 14:14:34 -05:00
collision.collider.health -= 1
2020-07-18 17:07:40 -05:00
queue_free()