Trouble finding perpendicular

Hi All,

I am building a cover system and I am stuck on determining what positions are considered IN COVER given an enemy position and a object that can be used as cover.

I have an object that functions as cover, like a barrel. This barrel has 8 different spot where you can hide around it.

Something like this with B bing the barrel and 0 a possible cover spot:

000
0B0
000

What I want to do is take the vector of the position of the enemy and the barrel to determine a perpendicular. I want to place that perpendicular on the barrel and any point that is behind the perpendicular is considered to be in cover.

An enemy to the right of the barrel would yield the following:

100
1B0 <--------> enemy
100

1 means the position is considered in cover.

So far I THINK I have the formula for the perpendicular, but my math is too rusty to know what to do with it. Can anyone help me out here?

Vector3 perpendicular = Vector3.Cross(cover.position - enemy.position, Vector3.up);

Looking at what your doing here, it seems to be right in getting the perpendicular vector from those vectors. It may be worth doing a dot product on your new vector, then anything less than 0 would be considered behind the perpendicular line.

float val= Vector3.dot(cover.position - enemy.position, (+/-)perpendicular);

If the val is < 0, it is behind that perpendicular line across the barrel.

I tried the following:

for(var y = 0; y < coverPositions.Count; y++)
{
        Vector3 perpendicular = Vector3.Cross(coverPositions[y].position - enemy.position, Vector3.up);
	float val= Vector3.Dot(coverPositions[y].position - enemy.position, perpendicular);
	Debug.Log (val + " " + coverPositions[y].position);
	
	if(val == 0)
	{
		coverPositions[y].renderer.material.color = Color.red;	
	}
	else
	{
		coverPositions[y].renderer.material.color = Color.gray;	
	}
}

Unfortunately, val is always zero. There is something wrong somewhere.

Edit:
I made a mistake with the perpendicular. I was calculation it with the cover position instead of the cover. It somewhat works now, but there is still a mistake in the formula for the perpendicular I think.

The result I am getting now is this:

000
0B0 <--------> enemy
111

The enemy is standing exactly on the same axis as the barrel, but instead of giving the positions behind the barrel, they are turned to the side.

Vector3 posC = new Vector3(0,1,0) + cover.position;
Vector3 perpendicular = Vector3.Cross(cover.position - enemy.position, posC - enemy.position).normalized;

for(var y = 0; y < coverPositions.Count; y++)
{
        float val = Vector3.Dot(coverPositions[y].position - enemy.position, perpendicular);
}

Solved. I should not have used the perpendicular.