While making a game in panda3d I have experienced a problem regarding my attempt to create a skybox.
The problem is this: I want it so that the camera cannot fly through the skybox or get closer to it. To achieve this I have created a task that gets the position of the camera and then moves the skybox to it. The task seems to work as the position of the camera remains the same as that of the skybox however in the game it looks as if the camera dos get closer. I have tried a few ideas to fix it but none have worked. Does anyone know what causes the problem and/or how to fix it ?
Here is the code:
This is main.py. The task that moves the skybox is at the bottom.
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
from player import *
from skybox import *
from direct.gui.OnscreenImage import OnscreenImage
import sys,time
class appclass (ShowBase) :
def __init__ (self) :
ShowBase.__init__(self)
base.disableMouse ()
base.enableParticles()
self.player = PlayerShip ()
self.spaceshipinteriorimageobject=OnscreenImage (image="textures/spaceships/spaceship1interior.png",scale=(2,1,1),pos= (0,0,0))
self.spaceshipinteriorimageobject.setTransparency(TransparencyAttrib.MAlpha)
self.skybox =SkyBox ()
taskMgr.add (self.skyboxlocationset,"skybox mover",sort=2)
def skyboxlocationset (self,task) :
cameraposition=base.camera.getPos (render)
self.skybox.model.setPos (render,cameraposition)
self.skybox.model.clearTexture()
self.skybox.model.setTexture(self.skybox.cubemap)
return task.cont
app=appclass ()
app.run ()
Here is skybox.py where the code that makes the skybox is.
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
class SkyBox () :
def __init__ (self):
self.model=loader.loadModel ("models/SkySphere.bam")
self.cubemap=loader.loadCubeMap ("textures/skybox/space_#.png")
self.model.setTexture (self.cubemap)
self.model.setScale (1000,1000,1000)
self.model.reparentTo (render)
And finally here is player.py. The two tasks at the bottom are the camera controls.
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
from panda3d.physics import *
class PlayerShip () :
def __init__ (self):
self.model=loader.loadModel ("models/spaceships/spaceship0")
self.model.setScale (8,8,8)
self.time=0.01666666666666666666666666666667 #TO BE REPLACED
self.model.setPos (0,0,0)
self.mass=10000
self.speed=0
self.engineforce=3000
self.ismovingforward=0
self.ismovingbackward=0
taskMgr.add (self.linearcontrols,"linearcontrols",sort=1)
taskMgr.add (self.mouselook,"look",sort=1)
def linearcontrols (self,task) :
self.acceleration=(self.engineforce/self.mass)
if base.mouseWatcherNode.isButtonDown ("w"):
self.speed+=(3*self.time)
if base.mouseWatcherNode.isButtonDown ("s"):
self.speed-=(3*self.time)
base.camera.setY (base.camera,self.speed)
return task.cont
def mouselook (self,task):
if base.mouseWatcherNode.hasMouse():
mousex=base.mouseWatcherNode.getMouseX()
mousey=base.mouseWatcherNode.getMouseY()
base.camera.setP(base.camera.getP()+mousey)
base.camera.setH(base.camera.getH()-mousex)
return task.cont