camera in specific coordinate

Hello,

I have a problem, I try to create a camera and put it in a specific coordinate. But as much as I can with this code below is place it inside an object

from direct.showbase.ShowBase import ShowBase

class MyApp (ShowBase):
def init __ (self):
ShowBase .
init __ (self)

self.scene = self.loader.loadModel (“environment”)
self.scene.reparentTo (self.render)
self.scene.setScale (12:25, 12:25, 00:25)
self.scene.setPos (2, 42, 0)

self.monkey = self.loader.loadModel (“macaco.egg”)
self.monkey.reparentTo (self.render)
self.monkey.setPos (0, 22, 1)
self.monkey.setH (225)

self.torus = self.loader.loadModel (“torus.egg”)
self.torus.reparentTo (self.render)
self.torus.setPos (-2, 22, 1)
self.torus.setH (225)

self.camera = base.camera
self.camera.reparentTo (self.torus)
self.camera.setPos (0, -250, 100)

app = MyApp ()
app.run ()

They could help me make it obey a coordinated and not a reference?

Hi and welcome to Panda3D!

I am not sure to understand your question, but if you want the camera to placed according to the base coordinate system, and not as a reference to something, you should use self.camera.reparentTo(render) instead of self.camera.reparentTo(self.torus). When you reparent the camera to torus, the camera position will be relative to the torus.

Note that scripting issues should go in the “scripting issues” section of the forum!

Also, you could use the Code bloc to share your code. That way, code is more easily read and it save space!

Yes I did self.camera.reparentTo (surrender) only that the coordinates do not change the self.camera.setPos (0, -250, 100)! Sorry for my english and thank pea help.

I made some test and there seems to be a bug! If you try to the camera at at the begging of the game, it won’t move. If you wait a little, it works. A way to go around the bug is to attach the camera to a NodePath and then move the NodePath as you would the camera. Here is an example below.

from direct.showbase.ShowBase import ShowBase

class MyApp (ShowBase):
	def __init__(self):
		ShowBase.__init__(self)

		self.scene = self.loader.loadModel("environment")
		self.scene.reparentTo(self.render)
		self.scene.setScale(12.25, 12.25, 0.25)
		self.scene.setPos(2, 42, 0)

		self.monkey = self.loader.loadModel("macaco.egg")
		self.monkey.reparentTo(self.render)
		self.monkey.setPos(0, 22, 1)
		self.monkey.setH (225)

		self.torus = self.loader.loadModel("torus.egg")
		self.torus.reparentTo(self.render)
		self.torus.setPos(-2, 22, 1)
		self.torus.setH (225)

		self.cameraNode = render.attachNewNode("CameraNode")
		self.camera.reparentTo(self.cameraNode)

		self.cameraNode.setPos(0, -150, 100)

app = MyApp ()
app.run ()

Again, I thing that this is not a normal behavior, but at least it is easily overcome!

EDIT: Edited the whole post, because on only had time to make a draft and didn’t wanted to lose it!

You need to call self.disableMouse() to prevent Panda from overwriting the position of the camera with the default camera controls.

Ok, it now make sense! Thanks for the clarification!