Raycast ignoring tags problem

Hi everyone, I don’t know whats wrong here. I using raycasts for my AI to avoid obstacles and I don’t want them to avoid some obstacles such as the player or obstacles that can be moved. But they avoid everything. So its suppose to avoid everything except player and movable objects, but instead it just avoids everything.

Here’s one snippet of the code. I have multiple raycasts but they’re all the same only with a different origin and ray distance.

if(Physics.Raycast(transform.position, transform.forward, hit, rayDistance1))
	{
		if(hit.collider.gameObject.tag != "Player" || hit.collider.gameObject.tag != "Movable" || hit.collider.gameObject.tag != "WeaponPickup");
		{
		Debug.DrawLine(transform.position, hit.point, Color.red);
		lookDirection += hit.normal * repelForce;
		}
	}
	else
	{
		Debug.DrawRay(transform.position, transform.forward * rayDistance1, Color.yellow);
	}

I don’t know whats wrong. I tried both hit.collider.tag != “Player” and hit.transform.tag != “Player” and the hit.collider.gameObject.tag != “Player”, but its the same result for anything.

Thank you.

Your tag IF is messed up – it’s always true. No matter what tag you hit, it’s always not the other two tags, so the answer is always true. Whenever you combine not-equals in an IF, should be using AND (&&) instead of OR. A good Intro to programming textbook might cover this in chapter 4.

Then a bunch of other things could be wrong. Check tags are set correctly. Print more stuff – the line after the raycast add print commands like Debug.Log("hit: "+ hit.transform);.