Weird movement =/

Im creating a simple space dog fighting game. im currently working on camera and ship controls i want the camera to follow the ship and also have its hpr be oriented to the ship. i figured reparenting the camera to the ship would do the trick but it puts it in the middle of the ship and i want it behind the ship and up a little so i added some camera.setX setY and setZ along with reparent to ship. it works but the camera either moves faster than the ship or the ship doesnt move. heres the code.

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.gui.OnscreenText import OnscreenText
import sys

class Main(object):
	def __init__(self):
		base.accept( "escape" , sys.exit)
		self.loadPlayer = Player() # Calls up the Player() class
		self.addlight() # load the light
	def addlight(self): #create the light
		ambientLight = AmbientLight('ambientLight')
		ambientLight.setColor(Vec4(.5, .5, .5, 1))
		ambientLightNP = render.attachNewNode(ambientLight)
class Player(object): # controls the Player
	speed = 5 # controls the speed of the ship
	FORWARD = Vec3(0, 2, 0) # sets direction and speed of forward direction
	STOP = Vec3(0, 0, 0)# sets the speed and direction of stop
	walk = STOP # makes walk = stop
	def __init__(self):
		self.loadShip() #calls up the function to load the ship
		taskMgr.add(self.updatePos, 'update position')
		taskMgr.add(self.mouseUpdate, 'update mouse')
	def loadShip(self): # just loads the ship model
		self.ship = loader.loadModel('ship')
	def loadWorld(self): # loads world = loader.loadModel('models/box'), 30, 3)
	def setCamera(self):
		place =
	def mouseUpdate(self,task):
		""" this task updates the mouse """
		md =
		x = md.getX()
		y = md.getY()
			self.ship.setP(self.ship.getP() -  (y -*0.1)
			self.ship.setH(self.ship.getH() - (x -*0.1)
		return task.cont
	def createControls(self):
		base.accept( "w" , self.__setattr__,["walk",self.FORWARD])
		base.accept( "w-up" , self.__setattr__,["walk",self.STOP] )

	def updatePos(self,task):
		self.ship.setPos(self.ship,self.walk*globalClock.getDt()*self.speed) - 10)
		return task.cont

any help would be great! :smiley:

You don’t want to put those in the updatePos task. Tasks are run every frame (when they return task.cont) so you are subtracting 10 from the Y every frame. Also, a node will move with its parent so you don’t need to continuously update it to match. Just parent it, set the Y to -10, and you’re done.

The changes:

Might as well put the camera code together…

    def setCamera(self):
       place =

and remove the unnecessary code from updatePos…

    def updatePos(self,task):
       return task.cont

I think that should work.

Thanks, I’ll give that a try. Seems like it should work :smiley:

EDIT: worked great! i feel like i tried that and it didnt work, but obviously i did it wrong XD. thanks :smiley: