First_Person_Slapper/Scenes/Enemy.gd

59 lines
1.3 KiB
GDScript3
Raw Normal View History

2022-10-11 19:11:46 -04:00
extends KinematicBody
var hit_acceleration = 10
var hit_speed = 100
var velocity = Vector3()
var movement = Vector3()
var direction = Vector3()
var gravity_vec = Vector3()
2022-10-11 21:21:27 -04:00
onready var hurtbox = $Hurtbox/HeadCollision
onready var hitbox = $HitBox/CollisionShape
2022-10-11 21:52:01 -04:00
onready var particles = $CPUParticles
onready var death_timer = $DeathTimer
onready var mesh = $MeshInstance
2022-10-11 21:24:46 -04:00
onready var Explosion = $Explosion
2022-10-11 21:21:27 -04:00
func _ready():
var rng = RandomNumberGenerator.new()
rng.randomize()
2022-10-11 19:11:46 -04:00
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)
2022-10-11 21:21:27 -04:00
if get_slide_count() > 0:
var collision = get_slide_collision(0)
if collision != null:
direction = direction.bounce(collision.normal)
2022-10-11 19:11:46 -04:00
2022-10-11 21:21:27 -04:00
func get_slapped(slap_level, slap_kill, slap_vector):
if slap_level >= slap_kill:
direction = slap_vector * slap_level
hurtbox.disabled = true
hitbox.disabled = false
2022-10-11 21:21:27 -04:00
func get_shot(hitboxOwner):
2022-10-11 21:24:46 -04:00
Explosion.play()
2022-10-11 21:57:37 -04:00
hitboxOwner.die()
2022-10-11 21:21:27 -04:00
die()
func die():
2022-10-11 21:52:01 -04:00
particles.emitting = true
hurtbox.disabled = true
hitbox.disabled = true
mesh.visible = false
death_timer.start(3)
func _on_DeathTimer_timeout():
queue_free()