Node origin and target are in the same position, look_at() failed

Godot Version

v.:4.1.1

Question

I have a problem that whenever my enemy crash into the wall this error occurs:

Node origin and target are in the same position, look_at() failed.

I do not understand why, because this only happens when the enemy cant reach the player (for example, when I jump somewhere where enemy can not reach, so the enemy is trying to get as close as possible). But everything is working as I wanted, that error just irritates me.

Here is Physics Process of enemy:

public override void _PhysicsProcess(double delta)
	{
		wallCheck.LookAt(new Vector3(player.Position.X, Position.Y, player.Position.Z), Vector3.Up);
        // raycast that detects walls

        var points = patrolPoints[_nextPointIndex].GlobalPosition;
	    var victim = player.GlobalTransform.Origin;
		var gotoTarget = points;

		if (wallCheck.IsColliding())
		{
			var Interaction = wallCheck.GetCollider() as StaticBody3D;

			if(Interaction != null)
			{
				Speed = 0f;
			}
		}


		if(Patrolling())// 2 states -  standing on points and walking to points
        {
			Patrol(); //patrol movement

            if(TargetFar())
        	{
				//WALKING
                Animations.Play(animWalk);
		    	Speed = wondSpeed;

				StateChange = false;// checks when can change state (set in animations)

				navAgent.TargetPosition = points;
        	}
			if(StateChange == true)
			{
            	if(TargetClose())
    	        {
					//STAYING

					Animations.Play(animIdle);
				   	Speed = 0f;

					StateChange = false;

					navAgent.TargetPosition = points;
         	   }
			}
        }
        else if(Seeking())// chasing - 2 states -  attacking and running
        {
			if(StateChange == true)
			{
            	if(TargetFar())
            	{
					//CHASING
      	          	Animations.Play(animRun);
			    	Speed = defSpeed;

					StateChange = false;

				    navAgent.TargetPosition = victim;
				}
            }
			if(StateChange == true)
			{
				if(TargetClose())
          		{
					//ATTACKING
                	Animations.Play(animAttack);
		    		Speed = atkSpeed;

					StateChange = false;

			   	 	navAgent.TargetPosition = victim;

			    	LookAt(new Vector3(player.GlobalPosition.X, GlobalPosition.Y, player.GlobalPosition.Z), Vector3.Up);
           		}
			}
        }


#region PATH SETUP
		var NextNavPoint = navAgent.GetNextPathPosition();
		Velocity = (NextNavPoint - GlobalTransform.Origin).Normalized() * Speed;
#endregion
		
#region ROTATION
		var rotation = new Quaternion(Basis).Normalized();

		LookAt(new Vector3(GlobalPosition.X + Velocity.X, GlobalPosition.Y, GlobalPosition.Z + Velocity.Z), Vector3.Up);

		var targetRot = new Quaternion(Basis).Normalized();
		Rotation = rotation.Slerp(targetRot, 0.15f).Normalized().GetEuler();
#endregion




		MoveAndSlide();
	}

I would post a video for better understanding, but I can not because Im new on godot forums. :confused:

2 Likes

Is this an error or a warning? The problem isn’t clear. Please reformat the question.

If the enemy velocity is zero it will be looking at itself. Which it can’t calculate.

2 Likes
#region ROTATION
		var rotation = new Quaternion(Basis).Normalized();

		if(Velocity != Vector3.Zero)
		{
			LookAt(new Vector3(GlobalPosition.X + Velocity.X, GlobalPosition.Y, GlobalPosition.Z + Velocity.Z), Vector3.Up);
		}
		else if(Velocity == Vector3.Zero)
		{
			LookAt(new Vector3(GlobalPosition.X, GlobalPosition.Y, GlobalPosition.Z), Vector3.Up);
		}


		var targetRot = new Quaternion(Basis).Normalized();
		Rotation = rotation.Slerp(targetRot, 0.15f).Normalized().GetEuler();
#endregion

I tryed this, but the error still occurs. It looks like that this line is now casuing it:

LookAt(new Vector3(GlobalPosition.X, GlobalPosition.Y, GlobalPosition.Z), Vector3.Up);

1 Like

Yea I would just get rid of that else side when it is zero.

I’ll pose this question to you, What is it trying to look at?

2 Likes

thank you so much - now I have 2 errors less somehow!

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.