Weird problem with lookAt

Hi there,

I am trying to create a boss fight for a game, and the basic operation I need is for the boss to move slowly until he looks at the player.

so my idea was to create a node attached to the boss (sentry).

self.innerCompass = self.sentryNode.attachNewNode(“InnerCompass”)

and then when the player come close enough to the boss, this node would look at the player


And then tell me the angle in the plane XY where the player is

print “Angle of compass”, self.sentry.innerCompass.getH()
print “Angle of compass”, self.sentry.innerCompass.getH(render)

and then use that difference to make the boss move slowly to face the player,

if(math.fabs(self.sentry.getH() - self.sentry.innerCompass.getH()>=0)):

elif(math.fabs(self.sentry.getH() - self.sentry.getCompassH()<0)):

But the problem is that, when I ask for the value of the H angle of the node that follows the player


Instead of giving me a value of 0 to 360, it gives me a weird value between 15 to 27 that does not make any sense at least to me, and I can not compare it with the H of the main node of the Boss.

Maybe there is something I do not understand about how lookAt works,

Thanks in advance for your help,

Perhaps it was getting the H relative to it’s parent, sentryNode?
But I think that this approach (using LerpIntervals) would be easier:

self.innerCompass = self.sentryNode.attachNewNode("InnerCompass")
i = LerpHprInterval(sentryNode, duration,self.innerCompass.getHpr(),self.sentryNode.getHpr()))
s = Sequence(i, name="bossMover")

Thank xboxjoshone,

I am doing it in a similar way, I am doing all this by placing that algorithm into a task, so the system is doing all this calculations,

  • pointing at the player with innerCompass (with LookAt)
  • Calculating the difference of the H angle between the boss and its InnerCompass
  • making a small change reducing that difference and making the boss move slowly to face the player
    -repeat all again.

The problem is that The H of innerCompass when it follows the player goes from the value 15 to 27 (no idea why), while I need to give to the boss a value between 0 and 360. But the two values do not make sense, I can not compare them.

Thank you for your help,

Like I said above, the innerCompass’s H may just be relative to your boss character. Try getting the boss’s H as well, add them together, and see if this is not what you want.

self.angle = self.sentryNode.getH() + self.compassNode.getH()

I put the boss still (means his Hpr is (0,0,0)) and rotate the player around the boss, and then I ask for the position of the innerCompas based on the boss and based on render

print "innerCompass only ", self.sentry.innerCompass.getHpr(render)
print "innerCompass with boss ", self.sentry.innerCompass.getHpr(),

but I get both the same value and still between 17 and 28 instead of 0 to 360. and the boss’ H is 0 so adding does not work :frowning:

weird I think there is something with the lookAt function I am doing wrong

Other sanity checks:

  • make sure your player visual is in the same place as the player node that you’re looking at
  • make sure you’re oriented such that heading is indeed the angle you want
  • specify an up-vector to make sure the HPR Panda finds for the look is the HPR you’re thinking of
  • keep in mind that intervals evaluate start and end points on creation, not on execution
  • keep in mind that lookAt is a one-time operation. I seem to recall there being a way to keep a node locked on target, but I don’t think lookAt is it.

Hi there,

sorry I had not written back in a while, but I had to move to another project for a while, But I think I found the solution to my own problem.

So the thing is that I was using this function this way:

 self.innerCompass.lookAt(render, playerPos) 

what this code does is to make the node InnerCompass to look at PlayerPos with reference to the render.

So having in mind that both, player and innerCompass are at the same high, (means that from the three angles of a node (Hpr) only H will be affected by this) Using, lookAt, I was getting a weird value from 0 to 180 to -180 to 0.

It is because of the result of the function atan2(x,y) (which gives you an angle in radians, between a central point and any other point in a plane) and its transformation to grades, (it always goes from 0 to 180 to -180 to 0).

There is a very simple function to transform this value into a 0 to 360

 ifself.innerCompass.getH(render) < 0:
                    theValue = self.innerCompass.getH(render) + 360
                    theValue = self.innerCompass.getH(render)

I hope this will help

i dont read everything, maybe your problem is already solved, but its pretty easy to get the radians in 2d. just in need of a bit of trigonometry to calculate the angel you need (sin(base/height)) and with you convert it to degrees. if you dont wantto you, just calulate it, you already know 360 is a circle.

▓▓▓ / ▒ |
▓▓/ ▒▒ |
▓/ ▒▒▒|height
/ ▒▒▒▒ |

x= player
O = target


or, like my first idea was, you can calculate the radian by time (before i knowed about trigomentry), but dont listen to me im such a solving freak, or you can raster it, or or or or there so many ways

but my conclusion will stay, you cant be reach more than your brain is able to imagin. ok there universtiities lol but anyway… yes i love universities, but im not so sure about there products :smiley: