I am trying to simulate an “auto-pilot” style function in my flying spaceship that will cause the ship to slowly rotate around to face opposite of it’s current direction of travel, then fire the engines until it stops in space.
I was planing on using hprInterval to do the rotation.
In order to make this work, I create 2 nodes at the ship’s current position. one parented to the ship, the other parented to render so it stops moving. I let the scene redraw a few times, then set the second temp node to lookAt(firstTempNode). Then, I use this line:
self.ship.hprInterval(5,Vec3(self.tempShipNode.getH(), self.tempShipNode.getP(), self.tempShipNode.getR()))
(tempShipNode is the one that is looking at the node that was at the ships previous location.)
If I use setHpr rather than hprInterval, it works fine, just doesn’t rotate in a natural looking method. Any ideas why the interval isn’t working out?
Also, if there is a better way, using a vector or something, I would love to hear about it.
For what it is worth, here is the code:
self.tempShipNode=self.ship.attachNewNode("tempShipNode") self.tempFacingNode = render.attachNewNode("tempFacingNode") self.tempFacingNode.setPos(self.ship.getPos())
Then, I run a task that executes 5 times, so there is time to get some distance between the two nodes. Then I use:
self.tempShipNode.lookAt(self.tempFacingNode) self.tempShipNode.wrtReparentTo(render) self.ship.hprInterval(5,Vec3(self.tempShipNode.getH(),self.tempShipNode.getP(),self.tempShipNode.getR()))
The wrtReparentTo is to get the node into render’s coordinate system instead of the ship’s.
Like I say, if I use:
Instead of the hprinterval, it works, but jumps rather than rotating nicely.
Thank you so much for any assistance!
edit: fix spelling error