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?
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.
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.