59 lines
1.3 KiB
GDScript
59 lines
1.3 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 particles = $CPUParticles
|
|
onready var death_timer = $DeathTimer
|
|
onready var mesh = $MeshInstance
|
|
onready var Explosion = $Explosion
|
|
|
|
func _ready():
|
|
var rng = RandomNumberGenerator.new()
|
|
rng.randomize()
|
|
|
|
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:
|
|
direction = slap_vector * slap_level
|
|
hurtbox.disabled = true
|
|
hitbox.disabled = false
|
|
|
|
func get_shot(hitboxOwner):
|
|
Explosion.play()
|
|
hitboxOwner.die()
|
|
die()
|
|
|
|
func die():
|
|
particles.emitting = true
|
|
hurtbox.disabled = true
|
|
hitbox.disabled = true
|
|
mesh.visible = false
|
|
death_timer.start(3)
|
|
|
|
|
|
func _on_DeathTimer_timeout():
|
|
queue_free()
|