hi.
lookAt is a very useful function, but it is instant.
i want to make a turret slowly track and line up a target.
i have a quat function that returns the difference between this and that angle. but how do i apply this quat to the turret in a way that 1.) take time and 2.) is interuptible or updatable if the target moves in a new unexpected direction.
AFAIK panda’s lerp functions are uninterruptible.
my code snippets so far (which i have scavenged mostly from the awesome posts on this board - top bunch of people here), which work but aren’t interruptible, are:
def quat_by_quat(self,base,obj2):
#takes 2 objects
# gets pos and quat of obj1
# get required quat to point at obj2
#return difference
obj1 = base
quat1 = obj1.getQuat()
pos1 = obj1.getPos()
obj1Dir = quat1.getForward()
obj1Dir.normalize()
#v = obj1Dir
vec2obj2 = obj2.getPos() - pos1
vec2obj2.normalize()
angleTowards = self.pointAt(base,obj2)
#print ("quat1 and asngeltwards" , quat1, angleTowards)
angleinQuat = Quat()
angleinQuat.setHpr(Vec3(angleTowards))
#print ("angle in quat is ", angleinQuat)
#qSubq = quat1 - angleinQuat
#print ("angle to turn is ",qSubq)
#obj1.setQuat(angleinQuat)
return angleinQuat
def pointAt(self, base,target):
self.tempNode = render.attachNewNode('tempNode')
self.tempNode.setPos(base.getPos())
self.tempNode.setHpr(base.getHpr())
self.tempNode.lookAt(target)
tempVec = self.tempNode.getHpr()
#print ("tempVec is", tempVec)
return tempVec
def turn_towards(self,base,angle,turnspeed):
myInterval1 = base.hprInterval(turnspeed, angle)
seq = Parallel(myInterval1)
seq.start()
and called with a function like
qAngle = self.quat_by_quat(self.ship_root,self.target)
self.turn_towards(self.ship_root,qAngle,self.turn_rate)
it’s my lack of experience again, but i need a way to break the quat result into a per second turn rate and then apply it to an objects rotation.it must be simpler than it seems but right now my lack of knowledge is confusing me.