20 lines
545 B
GDScript
20 lines
545 B
GDScript
extends CharacterBody3D
|
|
|
|
const ATTACK_IMPULSE = 40
|
|
const FRICTION = 1
|
|
|
|
func _physics_process(delta):
|
|
# Add the gravity.
|
|
if not is_on_floor():
|
|
velocity += get_gravity() * delta
|
|
velocity.x = move_toward(velocity.x, 0, FRICTION)
|
|
velocity.z = move_toward(velocity.z, 0, FRICTION)
|
|
|
|
move_and_slide()
|
|
|
|
func _on_player_attack(enemy_position: Vector3):
|
|
print("atakku", enemy_position)
|
|
var direction = (enemy_position - self.global_position).normalized()
|
|
look_at(direction * Vector3(1, 2, 1), Vector3.UP)
|
|
velocity += direction * ATTACK_IMPULSE
|