When I use lookAt() on my ship models they turn their back on target nodes, instead of their fronts. So I don’t want to turn all my models around in my modelling app and re-export to egg. I remember there is some option to change the coordinate system of loaded models or the game entirely (like Y-up, X-up etc).
mymodel.setPos(x, y, z) - this sets the X, Y, Z coordinates of the model. You can also pass in a single Vec3 variable instead of 3 seperate ones if you wish.
mymodel.setHpr® - rotates the model to face a new direction. r is the number of radians you which to move them (i.e. 180 would turn the model around completely to face the opposite direction).
You can also use mymodel.getPos() and mymodel.getHpr() to get the current position and facing direction of the model.
Also - I’m not entirely sure, but there probably is mymodel.setVpr() as well or some equivilant which you will probably need. The setHpr() function changes it’s facing along the horizontal (X) axis. So I imagine setVpr() will set it’s heading along the vertical (Y) axis, which will probably be very useful for a space game.
The lookAt() function probably isn’t working the way you are expecting because of the model’s position when it was exported. Depending on how it was facing in Blender or whatever application you built it with, it’s ‘front’ might be a completely different part of the model than you intended.
there is no setVpr. setHpr stands for Heading Pitch Roll.
while the rest of your post is generally true, it’s not bradamate’s problem. his objects are moving just fine, but when he does lookAt() the model’s behind is facing the target. so he has to rotate the model 180 after each lookAt as a workaround. so the question would be how to make lookAt look along a different axis by default.
No, the first answer is (at least in principle) correct. Your models are simply rotated incorrectly. It’s not a coordinate system problem.
It’s a common problem with models that are constructed so that the artist can see them in the face. In this case, the model is looking back at the artist out of the screen. But that’s the backward direction: the forward direction is into the screen.
Rotating your models is the correct way to solve this. There are lots of ways to rotate your models. Since you don’t want to rotate them in the modeling package, you can use egg-trans for static models, or egg-optchar for animated (Actor) models. I assure you they do work, so if it didn’t, reexamine what you did.
The other option is to rotate them after loading. One easy way is:
model = loader.loadModel('mymodel.egg')
model.setHpr(180, 0, 0)
The flattenLight() call here bakes the rotation into the vertices, so that future calls to lookAt() will pick up the new rotation, instead of replacing it.