For some reason, my code cannot find the node animation player even though I have it on my player! I cant tell if its something wrong with my code
extends KinematicBody
var speed = 10
var acceleration = 20
var gravity = 9.8
var jump = 5
var damage = 50
var mouse_sensitivity = 0.05
var direction = Vector3()
var velocity = Vector3()
var fall = Vector3()
onready var head = $head
onready var aimcast = $head/Camera/aimcast
onready var anim_player = $AnimationPlayer
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
head.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
head.rotation.x = clamp(head.rotation.x, deg2rad(-90), deg2rad(90))
func _process(delta):
direction = Vector3()
if Input.is_action_just_pressed("fire"):
if not anim_player.is_playing():
if aimcast.is_colliding():
var target = aimcast.get_collider()
if target.is_in_group("enemy"):
target.health -= damage
anim_player.play("assualt fire")
else:
anim_player.stop()
if Input.is_action_just_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.is_action_pressed("move_foward"):
direction -= transform.basis.z
elif Input.is_action_pressed("move_backward"):
direction += transform.basis.z
if Input.is_action_pressed("Move_left"):
direction -= transform.basis.x
elif Input.is_action_pressed("move_right"):
direction += transform.basis.x
direction = direction.normalized()
velocity = velocity.linear_interpolate(direction * speed, acceleration * delta)
velocity = move_and_slide(velocity, Vector3.UP)