Godot Version
Question
I am trying to make an enemy move towards a point depending on its current state with this function. However every time I try to run the game I get the same error: Invalid operands ‘Vector3’ and ‘Nil’ in operator '*.
func MoveTowardsPoint(delta, speed):
var targetPos = navigation_agent_3d.get_next_path_position()
var direction = global_position.direction_to(targetPos)
faceDirection(targetPos)
velocity = direction * speed
move_and_slide()
if(playerInEarshotFar):
CheckForPlayer()
The only time I call this function is in another function _process.
func _process(delta):
CheckForPlayer()
match currentState:
States.patrol:
if(navigation_agent_3d.is_navigation_finished()):
currentState = States.waiting
patrol_timer.start()
return
MoveTowardsPoint(delta, patrolSpeed)
pass
States.chasing:
if(navigation_agent_3d.is_navigation_finished()):
patrolTimer.start()
currentState = States.waiting
navigation_agent_3d. set_target_position(camera_3d.global_position)
MoveTowardsPoint(delta, ChaseSpeed)
pass
States.hunting:
if(navigation_agent_3d.is_navigation_finished()):
patrolTimer.start()
currentState = States.waiting
MoveTowardsPoint(delta, patrolSpeed)
pass
States.waiting:
CheckForPlayer()
pass
pass
The line giving the error is:
velocity = direction * speed
I have no idea how to fix the error and help would be greatly appreciated.