First_Person_Slapper/Scenes/Enemy.gd
Victor Turgeon d31b299251 monke
2022-10-11 21:21:27 -04:00

51 lines
1.1 KiB
GDScript

extends KinematicBody
var hit_acceleration = 10
var hit_speed = 100
var velocity = Vector3()
var movement = Vector3()
var direction = Vector3()
var gravity_vec = Vector3()
onready var hurtbox = $Hurtbox/HeadCollision
onready var hitbox = $HitBox/CollisionShape
onready var animation_player = $AnimationPlayer
func _ready():
animation_player.play("floating")
var rng = RandomNumberGenerator.new()
rng.randomize()
animation_player.seek(rng.randf_range(0.0,3.0))
animation_player.stop()
func _physics_process(delta):
velocity = velocity.linear_interpolate(direction * hit_speed, hit_acceleration * delta)
movement.x = velocity.x
movement.y = velocity.y
movement.z = velocity.z
move_and_slide(movement, Vector3.UP)
if get_slide_count() > 0:
var collision = get_slide_collision(0)
if collision != null:
direction = direction.bounce(collision.normal)
func get_slapped(slap_level, slap_kill, slap_vector):
if slap_level >= slap_kill:
animation_player.stop()
direction = slap_vector * slap_level
hurtbox.disabled = true
hitbox.disabled = false
func get_shot(hitboxOwner):
hitboxOwner.die()
die()
func die():
queue_free()