Return positive or negative based on which side an object is on?

Thanks to the guidance of some very helpful individuals, I managed to get turret tracking set up exactly how I had hoped :slight_smile: however I’ve run into another problem. Using .alignAxisToVect() doesn’t leave any room to set up a variable to keep track of the turret’s orientation (example, to lock rotating past -1 Y so the guns won’t shoot through the ship)

So the question is, if you’re using the ship as a reference point, is there a way to make the left cube return a negative number, and the right cube return a positive number? If so, the “shoot through the ship” problem would be very simple to solve. Sorry for the “newby” questions; this is my first attempt at making a serious, complex game with BGE (I came here from Unity as I absolutely DESPISE javascript and C#, heh). And an off-topic question as it’s been bugging me for some time- is there a way to disable auto-save on the forums? Every few seconds when the thread decides to auto-save my text, it’ll lock up my browser until it finishes, making typing anything of length a fun and exciting experience.

I believe you can use the dot product of the forwards vector against the line to the point. However the line to the point must be to the point at the same height

Sure it is. I assume left and right is on the x axis. Retrieve a vector along the local x axis (in world space) of the current object and do a dot product (also called scalar product) with the vector from the current object to the object in question.

If the dot product is negative the object is left if it is positive it is right. If it is zero the object is before,behinf,over or under the current object.


Got it, thanks everyone. I feel bad for asking so many simple questions around here, but I suppose you have to learn somehow :stuck_out_tongue:

i dont get it, can you post an example code?
sometimes its easier to me to read python than english lol

I think you should understand the math behind this rather then asking for ready to use code. Therefore I recommend to check wikipedia for dot product.

Anyway here is a demo. It includes some helpers to show how it works. They are the children of Alignment.leftRight.

The mathematics itself consists of three line Python code. I’m sure it is not that hard to find it.

You can use the included object to detect up/down and front/behind as well. Just parent it with the according orientation. It measures along Y-axis as the empties representation circle faces along Y. This makes it easier to see where the alignment plane is.


Alignment.blend (93.7 KB)

yep i understood the math, and i knew it couldnt be larger than 5 lines, its just that im not that experienced at python and sometimes i need a little push, thanks anyway Monster :smiley:

if you use a rigid body, and use a 6dof joint, and then have the rotation triggered by a sensor…Radar?

then it is just like a real gun…

real guns can’t turn through stuff…

Ok, try this out :slight_smile:

this works great and, does not have issues with physics, and you can slap them around, with physics :slight_smile:


TheRet.blend (515 KB)

You need to break it into a “base” and a gun, so that the 2-part motion can happen, but its easy, just add it, change the targets of the 6dof and messages :slight_smile:

BluePrintRandom, why are you writing about joints? This has nothing to do with the topic. And please do not add several posts. You can simply edit your last post.

the python method for scalar product is .dot

orientation1 = Vector([0,0,0])
orientation2 = Vector([1,0,0])
scalar =

thanks thats all i wanted to know :smiley:

this is another solution, please don’t tell me not to express my solutions
Download and run it,

it works, and can be timed:)

PLEASE don´t express your solutions, or if you make it, try not to spam

try not to ???


… Try not to post two or more posts in a row.