I know this is likely a regular scenario in the world of game development, and we, those who develop using the BGE would be no different in encountering these scenarios. You create a game mechanic, then try to enhance it, then due to concerns you might not be able to get it to work right if you tried altering what you got, you decided to scrub it and start over with a fresh overview and new ideas.
I had this situation recently with one of my games where you have to drive a car along various courses to the end concerning what I had set up for the camera to avoid as much clipping as possible, I thought at the time I would easily be able to achieve this camera system with what I had in my script, but then months later after doing other game projects that involved python I looked at the code again (posted below)
#--------Variables that are constantly set for camera related logic--------#
#only set RD1-4 variables when ray sensors are positive#
if DPX.positive==True:
RD1 = ob.getDistanceTo(HP1)
else:
RD1=30
if DPZ.positive==True:
RD2 = ob.getDistanceTo(HP2)
else:
RD2=30
if DNZ.positive==True:
RD3 = ob.getDistanceTo(HP3)
else:
RD3=30
if DNX.positive==True:
RD4 = ob.getDistanceTo(HP1)
else:
RD4=30
#set Rspectrum variable#
ob["RSpectrum"] = RD1+RD2+RD3+RD4/4
#---camera controls pre-curser, set variables important for the camera system---#
#move the camera itself under certain conditions#
if ob["C"]==0:
if ob["init2"] == 1 and Surface.positive==True and CamX.positive==False and CamXN.positive==False:
if Left.positive==True or Right.positive==True:
if ob["Limit"] < ob["Lmax"]:
ob["Limit"] += 0.004
if ob["Lfactor"] < ob["LFmax"]:
ob["Lfactor"] += 0.0125
else:
if ob["Lfactor"] > 0:
ob["Lfactor"] -= 0.0004
if ob["Limit"] > 0:
ob["Limit"] -= 0.00125
if VxL >= -5:
Cam_move.dLoc=[RzG/2.25*ob["Lfactor"]*ob["Limit"],0,0]
Cam_move.useLocalDLoc=True
c.activate(Cam_move)
elif VxL < -5 and VxL >= -35:
Cam_move.dLoc=[RzG/1.6*ob["Lfactor"]*ob["Limit"],0,0]
Cam_move.useLocalDLoc=True
c.activate(Cam_move)
elif VxL < -35:
Cam_move.dLoc=[RzG/1.3*ob["Lfactor"]*ob["Limit"],0,0]
Cam_move.useLocalDLoc=True
c.activate(Cam_move)
elif CamX.positive==True or CamXN.positive==True: #if the camera is about go through a vertical wall--
if CamX.positive==True and CamXN.positive==False:
Cam_move.dLoc=[1.5*ob["Lfactor2"]*ob["Limit2"],0,0]
Cam_move.useLocalDLoc=True
c.activate(Cam_move)
if CamXN.positive==True and CamX.positive==False:
Cam_move.dLoc=[-1.5*ob["Lfactor2"]*ob["Limit2"],0,0]
Cam_move.useLocalDLoc=True
c.activate(Cam_move)
#set Dlength#
if VxL < -2 and Fsight.positive==False and VzG >= -1 and ob["RD_G"] < 3:
ob["Dlength"]+= 0.18
else:
ob["Dlength"]=0
if DNY.positive==True:
ob["RD_G"] = ob.getDistanceTo(HP_G)
else:
ob["RD_G"]=15
#set Flength to 0 when Dlength is the correct value#
if ob["Dlength"] > 20:
ob["Flength"] = 0
if CamX.positive==False and CamXN.positive==False:
ob["Lfactor2"] = 0
ob["Limit2"] = 0
else:
if ob["Limit2"] < 1:
ob["Limit2"] += 0.004
if ob["Lfactor2"] < 1:
ob["Lfactor2"] += 0.0125
if Carcam.positive==True:
if ob["C"]==0:
ob["C"]=1
if ob["C"]==2:
ob["C"] = -1
#-----------------------------------CAMERA CONTROLS------------------------------------------#
#default position with no obstructions#
if ob["C"]>=1:
if ob["C"]==1:
c.deactivate(Cam)
ob.visible=False
Camera.position=(px, py-2.1, pz+2.3)
Camera.orientation = OrCam.orientation
Camera.setParent(ob, 0, 1)
ob["C"]=2
if ob["C"]<=0:
if ob["C"]== -1:
Camera.removeParent()
ob.visible=True
ob["C"]=0
if DPX.positive==False and DNZ.positive==False and DPZ.positive==False and DNX.positive==False:
Cam.max=26
Cam.min=26
Cam.height=7
Cam.useXY=False
c.activate(Cam)
ob["KeyMod"]=0
ob["Cooldown"]=1
ob["Lmax"]=1
ob["LFmax"]=1
#script for camera when on slopes, near obstructions, ect...#
if DPX.positive==True or DNZ.positive==True or DPZ.positive==True or DNX.positive==True:
#math to set the RSpectrum variable, and declare most of the large variable assortment for the camera values#
Divide_H = ob["RSpectrum"]/100
Divide_L = ob["RSpectrum"]/100
Hfactor = ob["RSpectrum"]*Divide_H
Dfactor = ob["RSpectrum"]*Divide_L
Sfactor = VzG*-0.5
Cfactor = -40+ob["RSpectrum"]*Divide_H/2.6
Divide_Fac=ob["CSmod"]/20
Afactor = ob["RSpectrum"]/29
CSmod2 = ob["RD_G"]*4
if VzG < 0.3 and VzG > -0.3:
ob["CSmod3"] = ob["RD_G"]-2.3783
else:
ob["CSmod3"] = ob["RD_G"]*4
#Avoid un-neccesary application of anti-clipping system for ramps by checking various conditions for Tlength#
if Left.positive==True or Right.positive==True:
if VzG < -0.4:
ob["Tlength"]+=1
elif VzG > -0.5 and ob["Tlength"] > 10 and VzG < 0.5:
ob["Tlength"]+=1
elif Fsight.positive==True and ob["Tlength"] > 40 and VzG > -0.5 and VzG < 0.5:
ob["Tlength"]+=1
else:
ob["Tlength"]=0
#Use all these variables to set KeyMod, which influences camera height, to make the camera more monkey proof#
if ob["Dlength"] < 20:
if VzG < -1 and ob["Flength"] < 1:
ob["Flength"] = 1
if Left.positive==True or Right.positive==True:
if ob["Tlength"] > 50:
ob["Flength"] = 2
if Foward.positive==True and VzG > 1 and ob["Flength"]>=2:
ob["Flength"]+=1
if ob["Flength"] >= 5 and ob["RD_G"] <= 3: #monkey proof shallower slopes--
ob["Cooldown"]+=0.3/CSmod2
ob["KeyMod"]=CSmod2*3/ob["Cooldown"]
elif ob["Flength"] >= 5 and ob["RD_G"] > 3: #monkey proof steeper slopes--
ob["Cooldown"]+=0.3/CSmod2/2.6
ob["KeyMod"]=CSmod2*3/ob["Cooldown"]
else:
ob["KeyMod"]=0
if ob["Flength"] < 10:
ob["Cooldown"]=1
#Limit Rspectrum to 400#
if ob["RSpectrum"] >= 400:
ob["RSpectrum"] = 385
#use the ray pointing down to boost the camera up slightly, to avoid clipping through the track in most remaining cases#
if ob["RD_G"] >= 3:
ob["CSmod"]=ob["RD_G"]*8
else:
ob["CSmod"]=1
#Create limit for Cslide variable to avoid too high a multiplier for Camera height#
if Cfactor >= 5:
ob["Cslide"] = 5-ob["RSpectrum"]/10
else:
ob["Cslide"] = Cfactor
#only use these camera values when Rspectrum or VzG is below or above a certain value, simple math is used to produce the sliding#
#values#
if ob["RSpectrum"] <= 160: #spectrum band below 160
if ob["RSpectrum"] > 67:
ob["Lmax"]=0.25
ob["LFmax"]=0.25
if VzG < 1 or ob["RSpectrum"] < 67: #VzG < 1 or spectrum band below 67
ob["Lmax"]=0.1
ob["LFmax"]=0.1
if VzG > 0.5:
Cam.max=26
Cam.min=26
else:
if VzG < -0.3:
Cam.max=26+ob["RSpectrum"]/Dfactor*10
Cam.min=26+ob["RSpectrum"]/Dfactor*10
Cam.height=ob["RSpectrum"]/Hfactor-ob["Cslide"]+ob["CSmod"]/2.4+ob["KeyMod"]
else:
if VzG > -0.3:
Cam.max=26
Cam.min=26
else:
Cam.max=26+ob["RSpectrum"]/Dfactor*10
Cam.min=26+ob["RSpectrum"]/Dfactor*10
Cam.height=ob["RSpectrum"]/Hfactor*Sfactor+6-Divide_Fac+ob["KeyMod"]
#for the spectrum band above 200, both cases testing for positive or negative Z-velocity#
elif ob["RSpectrum"] > 200 and VzG < 1.5:
Cam.max=26+ob["RSpectrum"]/Dfactor
Cam.min=26+ob["RSpectrum"]/Dfactor
Cam.height=ob["RSpectrum"]/Hfactor*Sfactor+Afactor/2.5+ob["CSmod3"]+ob["KeyMod"]
elif ob["RSpectrum"] > 200 and VzG > 1.5:
Cam.max=26+ob["RSpectrum"]/Dfactor*10
Cam.min=26+ob["RSpectrum"]/Dfactor*10
Cam.height=ob["RSpectrum"]/Hfactor-ob["CSmod"]/4+ob["KeyMod"]
else:
Cam.max=26+ob["RSpectrum"]/Dfactor
Cam.min=26+ob["RSpectrum"]/Dfactor
Cam.height=ob["RSpectrum"]/Hfactor*Sfactor+Afactor-ob["RD_G"]+ob["KeyMod"]
Cam.useXY=True
c.activate(Cam)
see below…