cameraviewport help plz?
Blitz3D Forums/Blitz3D Beginners Area/cameraviewport help plz?
| ||
Hi folks, After downloading B3d about 2 weeks ago, I'm now well and truly into my first project. It's a 3d fly anywhere space shooter and I'm amazed at how easy this language is to use. Here's a problem which I hope someone with more brains than me can help me with. I've set up a camera with it's own viewport which occupies the bottom right corner of the screen. For some reason I cant get it to work with my main camera(called 'fwdcam'). When I switch to cockpit view(cockpitcam) by pressing '4' or actioncam by pressing '3' my radar is working perfectly with these cameras but it will not work when the forward camera is selected. I've been trying to figure this one out for about 5 hours now. Here is the code ________________________ Global X3D#,Y3D#,Z3D#,resx,resy SetBuffer BackBuffer() Global xrotation#,zrotation#,acceleration#,roll#,pitch#,a,campoint%,shippoint%,firedn#,enemycount Global rview,HitEntity#,HitDistance#,shield,mineshield,enemybullet,center,msight,msight1 Global fwdcam,rvcam,actioncam1,cockpitcam,camera,pvt,radarcam,sph,bullet,wehit,explodevol#,expl,trails,radarship Global missile,msite,srotation,missSpd#,mrot#,launched%,target,sight%,targetent Global rkeydown,rzoom#,timer,fps,temp,gtime,buldist,ship Include "intro.bb" resx=1024 resy=768 Graphics3D resx,resy,32,1 ;GLOBAL SOUND FILES Global sndshoot,chnship,sndexplode,sndwehit,sndwoosh Type t2dI3d Field X#,Y#,Z#,W#,H#,Camera% End Type Type particle Field mx#,my#,mz#,count,entity End Type Type explode Field mx#,my#,mz#,count#,entity End Type Type missile Field targetent,entity End Type Type bullet Field mx#,my#,count,entity End Type Type enemybullet Field ebx#,eby#,count,entity,sndplayed End Type Type enemy Field entity,ca%,ct%,spx#,spd#,spz# End Type Type radarpoint Field parent, entity End Type ;CONSTANTS Const player = 1, land = 2, lazer = 3, aliens = 4,enbullet = 5, mine = 6 Const chase = 1, goback = 2, climb = 3, base = 4, loopleft = 5, loopright = 6 Const ExplodeSize = 20, ExplodeIntensity = 70, ExplodeScale = 50 Const radarht = 155000, radarrange = 15000 ;Create CENTER center = CreatePivot() MoveEntity center,0,7000,0 ;CREATE PVT pvt = CreatePivot() EntityType pvt,player EntityRadius pvt,25 ;CREATE PARTICLE Print "Loading particle meshes." sph = LoadSprite( "media/exhaust.bmp" ) ScaleSprite sph,1,1 HideEntity sph ;CREATE TRAILS trails = LoadSprite("media/trail.bmp") ScaleSprite trails,3,3 HideEntity trails ;CREATE EXPLOSION PARTICLES expl = LoadSprite( "media/exhaust.bmp" ) ScaleSprite expl,10,10 HideEntity expl ;CREATE BULLET Print "Loading weapon meshes." bullet = LoadMesh("media/bullets.3ds") RotateMesh bullet,-90,180,0 EntityType bullet, lazer ScaleEntity bullet,3.5,3.5,5 EntityColor bullet,255,255,0 EntityRadius bullet,8 HideEntity bullet ;CREATE MISSILE missile = LoadMesh ("media/missile.3ds") RotateMesh missile,90,180,0 EntityType missile, lazer EntityRadius missile, 6 HideEntity missile ;CREATE ENEMYBULLET enemybullet = LoadMesh("media/enemybullet.3ds") RotateMesh enemybullet,-90,180,0 EntityType enemybullet, enbullet ScaleEntity enemybullet,.2,.2,3 EntityRadius enemybullet,2 EntityColor enemybullet,255,255,100 HideEntity enemybullet ;CREATE SHIP Print "Loading craft meshes." ship = LoadMesh("media/ship.3ds",pvt) EntityShininess ship,1 RotateMesh ship,-90,180,0 ScaleEntity ship,1.5,1.5,1.5 ;CREATE TARGETING SPOT tget = LoadSprite ("media/radarenemy.jpg",1,pvt) ScaleSprite tget,30,30 MoveEntity tget,0,0,10000 EntityColor tget,120,255,120 EntityOrder tget,-1 ;CREATE MISSILE SIGHT msight = LoadSprite("media/missilesight.bmp") ScaleSprite msight,.3,.3 EntityColor msight,255,0,0 msight1 = CopyEntity (msight) ScaleSprite msight1,.5,.5 EntityColor msight1,255,180,0 Print "Creating radar sprites." ;CREATE RADAR radarcam = CreateCamera() CameraZoom radarcam,1 PositionEntity radarcam,0,radarht,0 CameraRange radarcam,1,radarrange PointEntity radarcam,center CameraViewport radarcam,(resx/4)*3,(resy/4)*3,resx/4,resy/4 radarship = LoadSprite ("media/radarship.jpg") ScaleSprite radarship,700,700 ;CREATE RADAR POINTS radarenemy = LoadSprite ("media/radarenemy.jpg") EntityColor radarenemy,255,0,0 ScaleSprite radarenemy,200,200 HideEntity radarenemy Print "Setting up cameras." ;CREATE FWDCAM fwdcam = CreatePivot() ;CREATE RVCAM rvcam=CreatePivot(fwdcam) MoveEntity rvcam,0,10,70 PointEntity rvcam,ship ;CREATE actioncam1 actioncam1=CreatePivot(pvt) MoveEntity actioncam1,50,10,-70 PointEntity actioncam1,ship ;CREATE cockpitcam cockpitcam=CreatePivot(pvt) MoveEntity cockpitcam,0,0,3 ;PointEntity cockpitcam,ship ;CREATE CAMERA camera = CreateCamera(fwdcam) MoveEntity camera,0,7,-8 CameraRange camera,1,20000 Print"Creating light source." ;CREATE LIGHT light = CreateLight() LightColor light,255,255,255 PositionEntity light,0,100000,0 RotateEntity light,90,0,0 ;WIREFRAME WireFrame 0 Print "Loading Terrain." ;CREATE TERRAIN ;terrain = LoadTerrain("media/hmap_1024.jpg") ;TerrainShading terrain,False ;ScaleEntity terrain,12,1400,12 ;TerrainDetail terrain,4000,True ;PositionEntity terrain,-24000,-1000,-24000 terrain = CreatePlane() PositionEntity terrain,0,-1000,0 terrain_tex = LoadTexture("media/grass.bmp",1) ScaleTexture terrain_tex,100,100 EntityTexture terrain,terrain_tex EntityType terrain,land ;CREATE MINESITE msite = LoadMesh("media/minesite.3ds") tex = LoadTexture("media/metal027.jpg") EntityTexture msite,tex RotateMesh msite,-90,180,0 ScaleMesh msite,250,250,250 EntityColor msite,50,50,50 EntityType msite,mine ;EntityRadius msite,300 PositionEntity msite,0,-1000,0 ;PositionEntity msite,0,TerrainY(terrain,0,0,0),0 EntityColor msite,255,255,255 Print "Loading enemy meshes." ;CREATE ENEMY enemy1 = LoadMesh("media/enemy.3ds",center) RotateMesh enemy1,-90,180,0 ScaleEntity enemy1,5,5,5 EntityRadius enemy1,40 EntityType enemy1, aliens HideEntity enemy1 Print "Loading sounds." ;LOADSOUNDS sndshoot = LoadSound ("media/sounds/pshoot.wav") sndexplode = LoadSound ("media/sounds/explode.wav") sndwehit = LoadSound ("media/sounds/hit.wav") sndship = LoadSound ("media/sounds/Cabin.wav") sndwoosh = LoadSound ("media/sounds/email.wav") ;Initialise Print "Initialising" Collisions player,land,2,2 Collisions lazer,aliens,1,2 Collisions enbullet,player,1,2 Collisions enbullet,mine,2,2 Collisions aliens,land,2,2 Collisions aliens,aliens,1,2 init2Din3D(camera,15,resx,resy) shield = 100 rzoom = 1 ;chnMusic = PlayMusic("media/sounds/guitar.wav") LoopSound sndship SoundVolume sndship,1 chnship =PlaySound(sndship) acceleration = 10 PositionEntity pvt,4000,7000,14000 PointEntity pvt,msite NoOfEnemy = 50 ;As many as you like. If your system can handle it, try 300 + :) ;GAME LOOP<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> While Not KeyDown(1) gtime = gtime +1 ;SPAWN ENEMY If EnemyGenCount<NoOfEnemy And gtime Mod 5 =0 EnemyGenCount = EnemyGenCount +1 e.enemy = New enemy e\entity = CopyEntity(enemy1) EntityParent e\entity,0 e\ca% = base e\ct%= 30000 e\spx = .6 ;climb speed e\spz = 1.3 ;roll speed e\spd = 16;forward speed PositionEntity e\entity,Rnd(10,500),7000,9000 Ra.radarpoint = New radarpoint Ra\parent = e\entity Ra\entity = CopyEntity(radarenemy) End If EnemyAI() CheckChangeCamera() UpdateBullets() MoveShip() UpdateEnemyBullets() UpdateExplosions() UpdateExhaustParticles() ShipRoll(xrotation#,zrotation#) UpdateRadar() MoveCamera() LaunchAndControlMissiles() UpdateWorld RenderWorld Text 0,FontHeight(),"Enemy Count: "+enemycount Text 0,FontHeight()*2, "Roll:"+r# Text 0,FontHeight()*4, "Mine Shileds: "+mineshield Text 0,FontHeight()*5,"Shield:"+shield GetFPS() Text 0,FontHeight()*7,"fps:"+fps Text 0,FontHeight()*8,"distance: "+buldist Flip Wend End ;____________________________________________________________________________________________ Function LaunchAndControlMissiles() If KeyDown(20)And sight=0 Then sight = 1;this variable is set when the sights are displayed ShowEntity msight ShowEntity msight1 End If If sight = 1 srotation=srotation+2 If srotation > 360 Then srotation = 1 RotateSprite msight,srotation RotateSprite msight1,-srotation If target= 0 Then;This variable is set to 1 when a target is selected. To3d(resx/2,resy/2);center the sight on the screen. PositionEntity msight,x3d,y3d,z3d PositionEntity msight1,x3d,y3d,z3d For e.enemy = Each enemy ;cycle through each enemy and determine if they are in the sights. EntityParent e\entity,pvt pvtx=EntityX(e\entity,False) pvty=EntityY(e\entity,False) pvtz=EntityZ(e\entity,False) If pvtx>-30 And pvtx<30 And pvty>-30 And pvty<30 And pvtz >30 target = 1; set the target variable. targetent = e\entity End If EntityParent e\entity,0 Next Else If EntityInView(targetent,camera) = True CameraProject(camera,EntityX(targetent),EntityY(targetent),EntityZ(targetent)) to3d(ProjectedX(),ProjectedY());position the sight over the target. PositionEntity msight,x3d,y3d,z3d PositionEntity msight1,x3d,y3d,z3d End If End If End If If KeyDown(57) And target = 1 And launched = 0 launched = 1;this variable is set when a missile is in flight missSpd# = 15 +acceleration# m.missile = New missile m\entity = CopyEntity(missile,pvt) m\targetent = targetent mrot# = 0.05 ;this variable controls the amount of turn.Ensuring it starts of flying very straight for a short distance before turning towards the target. chnMissile = PlaySound(sndshoot) ChannelPitch chnMissile,9000 EntityParent(m\entity,0) End If If launched = 1 For m.missile = Each missile EntityParent m\targetent,m\entity mpvtx=EntityX(m\targetent,False) mpvty=EntityY(m\targetent,False) If mrot < 1 Then mrot# = mrot# * 1.05 End If ;Rotate z ; If mpvtx<-2 ; msy#=mrot# ; Else ; If mpvtx>2 ; msy#=-mrot# ;This code rotates the missile towards its target. End If ; End If ; ;rotate x ; If mpvty<-2 ; msx#=mrot# ; Else ; If mpvty>2 ; msx#=-mrot# ; End If ; End If ; EntityParent m\targetent,0 ; TurnEntity m\entity,msx#,msy#,msz# ; If EntityDistance(m\targetent,m\entity) <50 Then PointEntity m\entity,m\targetent missSpd# = missSpd#*1.005 If missSpd#>20 Then missSpd# = 20 MoveEntity m\entity,0,0,missSpd# ;Check for collision with target and explode. cc= CountCollisions(m\entity) If cc<>0 HitEntity = m\targetent launched = 0 target = 0 targetent = 0 sight = 0 missSpd = 0 FreeEntity m\entity Delete m HideEntity msight HideEntity msight1 chnexplode = PlaySound(sndexplode) CreateExplosion(HitEntity,ExplodeSize,ExplodeIntensity,ExplodeScale) End If Next End If End Function Function ShipRoll(xrotate#,zrotate#) roll#=roll#+zrotate# pitch#=pitch#+xrotate# roll#=roll#*.9 pitch# = pitch# *.9 TurnEntity pvt,pitch#,0,roll# xrotation# = 0 zrotation# = 0 ;accelerate the ship MoveEntity pvt,0,0,acceleration# End Function Function MoveCamera() fparent=GetParent(fwdcam) EntityParent(fwdcam,pvt,True) dx#=EntityX(fwdcam) dy#=EntityY(fwdcam) dz#=EntityZ(fwdcam) r#=EntityRoll(fwdcam) p#=EntityPitch(fwdcam) y#=EntityYaw(fwdcam) If r# => 180 Then r# = r# - 360 If r# =< -180 Then r# = r# + 360 TurnEntity fwdcam,-p#,-y#,-r#*.03 TranslateEntity fwdcam,-dx*.1,-dy*.1,-(dz+10)*.5 EntityParent(fwdcam,0) End Function Function CreateBullet() b.bullet = New bullet b\count = 200 b\mx# = Rnd(-1.1,1.1) b\my# = Rnd(-1.1,1.1) b\entity = CopyEntity(bullet,pvt) MoveEntity b\entity,0,0,15 EntityParent b\entity,0 TurnEntity b\entity,b\mx#,b\my#,0 ScaleEntity b\entity,3.5,3.5,35 PlaySound(sndshoot) End Function Function UpdateEnemyBullets() For eb.enemybullet = Each enemybullet;MOVE ENEMY BULLETS eb\count = eb\count - 1 ;Check distance of bullet to player. Play woosh sound if close. buldist = EntityDistance(eb\entity,pvt) If buldist < 125 And eb\sndplayed = False Then eb\sndplayed = True StopChannel chnwoosh chnwoosh = PlaySound(sndwoosh) ChannelPitch chnwoosh,5000 End If ;Check for collision with player If EntityCollided(eb\entity,player) Then wehit = CollisionEntity(eb\entity,1) shield = shield - 5 cc = 0 For q=1 To 30 f1.explode=New explode f1\count=50 f1\mx#=Rnd(-2,2) f1\my#=Rnd(-2,2) f1\mz#=10 f1\entity=CopyEntity(expl,eb\entity) EntityColor f1\entity,255,0,0 ScaleSprite f1\entity,2,2 EntityParent f1\entity,0 Next PlaySound(sndwehit) TurnEntity pvt,Rnd(-15,15),Rnd(-15,15),Rnd(-15,15) ;createexplosion(wehit,ExplodeSize,ExplodeIntensity) End If ;Check for collision with Base If EntityCollided(eb\entity,mine) Then eb\count = 0 mineshield = mineshield - 10 createexplosion(eb\entity,20,20,45) ;PlaySound(sndwehit) End If If eb\count Mod 5 = 1 f1.explode=New explode f1\count=40 f1\entity=CopyEntity(trails,eb\entity) EntityColor f1\entity,255,0,255 ScaleSprite f1\entity,4,4 EntityParent f1\entity,0 End If If eb\count > 1 Then MoveEntity eb\entity,eb\ebx#,eb\eby#,90 Else FreeEntity eb\entity Delete eb End If Next End Function Function UpdateRadar() If KeyDown(19) And rkeydown = 0 rzoom = rzoom + 0.5 rkeydown = 1;This variable prevents this routine from running continuously while the r key is held down If rzoom >3 Then rzoom = 1 End If CameraZoom radarcam,rzoom End If If (Not KeyDown(19)) And rkeydown = 1 rkeydown = 0 End If For ra.radarpoint = Each radarpoint PositionEntity ra\entity,EntityX(ra\parent),radarht-(radarrange-1000),EntityZ(ra\parent),True Next RotateEntity (radarcam,90,EntityYaw#(pvt,True),0,True) PositionEntity (radarcam,EntityX(pvt,True),radarht,EntityZ(pvt,True),True) PositionEntity (radarship,EntityX(pvt,True),radarht-1000,EntityZ(pvt,True),True) End Function Function CheckChangeCamera() If KeyDown(2) Then FreeEntity camera camera = CreateCamera(fwdcam) MoveEntity camera,0,7,-8 CameraRange camera,1,20000 End If If KeyDown(3) Then FreeEntity camera camera = CreateCamera(rvcam) CameraRange camera,1,20000 End If If KeyDown(4) Then FreeEntity camera camera = CreateCamera(actioncam1) CameraRange camera,1,20000 End If If KeyDown(5) Then FreeEntity camera camera = CreateCamera(cockpitcam) CameraRange camera,1,20000 End If End Function Function MoveShip() If KeyDown(200);x rotation(pitch) xrotation# = .15 Else If KeyDown(208) xrotation# = -.15 EndIf If KeyDown(203);z rotation(roll) zrotation# = .15 Else If KeyDown(205) zrotation# = -.15 EndIf If KeyDown(30);Distance (z) movement acceleration# =acceleration# +.3 If acceleration#>17 Then acceleration =17 Else If KeyDown(44) acceleration# = acceleration# -.3 If acceleration <.3 Then acceleration = 0.3 EndIf ChannelPitch chnship,2000+(acceleration# * 600) ;create bullet if fire pressed. If KeyDown(29) And firedn = 0 Then CreateBullet() firedn = 1 End If If (Not KeyDown(29)) And firedn = 1 CreateBullet() firedn = 0 End If End Function Function CreateExplosion(HitEntity,ES,EI,ESC) If HitEntity<>0 Then m.missile = First missile If HitEntity = targetent launched = 0 target = 0 targetent = 0 sight = 0 missSpd = 0 If m.missile <> Null FreeEntity m\entity Delete m End If HideEntity msight HideEntity msight1 End If For h = 1 To EI f1.explode=New explode f1\count=Rnd(20,100) f1\mx#=Rnd(-ES,ES) f1\my#=Rnd(-ES,ES) f1\mz#=Rnd(-ES,ES) f1\entity=CopyEntity(expl,HitEntity) ScaleSprite f1\entity,ESc,ESc If Rnd(0,6)>5 Then EntityColor f1\entity,Rnd(0,128),Rnd(0,128),255 Else EntityColor f1\entity,255,Rnd(255),0 End If EntityParent f1\entity,0 Next For del.enemy = Each enemy If del\entity = HitEntity For delra.radarpoint = Each radarpoint If delra\parent = HitEntity FreeEntity delra\entity Delete delra End If Next FreeEntity del\entity Delete del EndIf Next If hitentity = pvt Then dead = 1 End If ;HitEntity = 0 End If End Function Function UpdateExplosions() For f1.explode=Each explode f1\count = f1\count -1 If f1\count>0 MoveEntity f1\entity,f1\mx#*(f1\count/60),f1\my#*(f1\count/60),f1\mz#*(f1\count/60) RotateSprite f1\entity,f1\count*3 alph# = f1\count/40 EntityAlpha f1\entity,alph# f1\mx#=f1\mx#/1.2 f1\my#=f1\my#/1.2 f1\mz#=f1\mz#/1.2 Else FreeEntity f1\entity Delete f1 EndIf Next End Function Function UpdateBullets() For b.bullet = Each bullet;MOVE BULLETS b\count = b\count - 1 If b\count > 1 Then MoveEntity b\entity,0,0,200 cc = CountCollisions(b\entity) If cc>0 Then HitEntity = CollisionEntity(b\entity,1) hitdistance = b\count b\count = 1 cc = 0 ChannelVolume chnexplode,1 chnexplode = PlaySound(sndexplode) CreateExplosion(HitEntity,ExplodeSize,ExplodeIntensity,ExplodeScale) End If Else FreeEntity b\entity Delete b End If Next End Function Function UpdateExhaustParticles() If acceleration#>1 Then For h = 1 To 1 f.particle=New particle f\count#=10 f\mx#=Rnd(-0.05,.05) f\my#=Rnd(-0.05,.05) f\mz#=-1 f\entity=CopyEntity(sph,pvt) EntityColor f\entity,100,100,255 MoveEntity f\entity,Rnd(-.1,.1),.05,-4 Next End If For f.particle=Each particle f\count# = f\count# -1 If f\count>0 EntityAlpha f\entity,(f\count#*.1) MoveEntity f\entity,f\mx#,f\my#,f\mz#-(acceleration*.04) Else FreeEntity f\entity Delete f EndIf Next End Function Function Init2DIn3D(Camera,Z#=4,ResW=0,ResH=0) If ResW <= 0 Then ResW = GraphicsWidth() If ResH <= 0 Then ResH = GraphicsHeight() P = CreatePlane(1) EntityPickMode P,2 PositionEntity P,EntityX(Camera,1),EntityY(Camera,1),EntityZ(Camera,1),1 RotateEntity P,EntityPitch(Camera,1),EntityYaw(Camera,1),EntityRoll(Camera,1),1 MoveEntity P,0,0,Z# TurnEntity P,-90,0,0 CameraPick Camera,0,0 While PickedEntity() <> P And Z# > 1.0 Z# = Z# - .1 MoveEntity P,0,.1,0 CameraPick Camera,0,0 Wend If Z < 1.0 Or PickedEntity() <> P Then RuntimeError "2d in 3d error" TFormPoint PickedX(),PickedY(),Z,0,Camera X# = Abs TFormedX() Y# = Abs TFormedY() i.t2dI3d = New t2dI3d i\X = X : i\Y = Y : i\Z = Z : i\W = ResW : i\H = ResH : i\Camera = Camera FreeEntity P End Function Function To3D(X#,Y#,TFormGlobal = 0,TFormTo=0) i.t2dI3d = First t2dI3d X# = -i\X + ((X# / i\W) * (i\X * 2)) Y# = i\Y - ((Y# / i\H) * (i\Y * 2)) If TFormGlobal = 0 Then TFormPoint X,Y,i\Z,i\Camera,TFormTo X3D = TFormedX() : Y3D = TFormedY() : Z3D = TFormedZ() Return EndIf X3D = X : Y3D = Y : Z3D = i\Z Return End Function Function GetFPS() If timer + 1000 <= MilliSecs() timer = MilliSecs() fps = temp-gtime temp = gtime End If End Function Function EnemyAI() ;ENEMY AI*************** enemycount = 0 ;e\ca - enemy's current action ;e\ct - enemy's time left performing current action For e.enemy = Each enemy If e\ca% = chase;CHASE EntityParent ship,e\entity pvtx=EntityX(ship,False) pvty=EntityY(ship,False) ;Rotate z based on x position If pvtx<10 tz#=e\spz Else If pvtx>10 tz#=-e\spz End If End If ;rotate x based on y If pvty<10 tx#=e\spx Else If pvty>10 tx#=-e\spx End If End If EntityParent ship,pvt TurnEntity e\entity,tx#,ty#,tz# ;if facing player fire bullet. If pvtx>-20 And pvtx<20 And pvty>-20 And pvty<20 And Rnd(1,200)>180 eb.enemybullet = New enemybullet eb\count = 100 eb\ebx# = Rnd(-2.5,2.5) eb\eby# = Rnd(-2.5,2.5) eb\entity = CopyEntity(enemybullet,e\entity) eb\sndplayed = False EntityParent eb\entity,0 End If tx#=0 ty#=0 tz#=0 End If If e\ca% = goback;GOBACK EntityParent center,e\entity pvtx=EntityX(center,False) pvty=EntityY(center,False) ;Rotate z based on x position If pvtx<-2 tz#=e\spz Else If pvtx>2 tz#=-e\spz End If End If ;rotate x based on y If pvty<-2 tx#=e\spx Else If pvty>2 tx#=-e\spx End If End If EntityParent center,0 TurnEntity e\entity,tx#,ty#,tz# End If If e\ca% = base;Attack Base EntityParent msite,e\entity pvtx=EntityX(msite,False) pvty=EntityY(msite,False) ;Rotate z based on x position If pvtx<20 tz#=e\spz Else If pvtx>20 tz#=-e\spz End If End If ;rotate x based on y If pvty<20 tx#=e\spx Else If pvty>20 tx#=-e\spx End If End If EntityParent msite,0 TurnEntity e\entity,tx#,ty#,tz# ;if facing base fire bullet. If pvtx>-40 And pvtx<40 And pvty>-40 And pvty<40 And Rnd(1,200)>198 eb.enemybullet = New enemybullet eb\count = 150 eb\ebx# = Rnd(-3.5,3.5) eb\eby# = Rnd(-3.5,3.5) eb\entity = CopyEntity(enemybullet,e\entity) EntityParent eb\entity,0 End If tx#=0 ty#=0 tz#=0 End If If e\ca% = climb;CLIMB If EntityPitch(e\entity,True)>-65 TurnEntity e\entity,-e\spx,0,0 End If If EntityRoll(e\entity,True)<-10 TurnEntity e\entity,0,0,e\spz Else If EntityRoll(e\entity,True)>10 TurnEntity e\entity,0,0,-e\spz End If End If End If If e\ca% = loopleft ;LOOPLEFT If EntityRoll(e\entity,True)<-90 TurnEntity e\entity,0,0,e\spz End If If EntityRoll(e\entity,True)>-90 TurnEntity e\entity,0,0,-e\spz End If If EntityPitch(e\entity,True)<0 TurnEntity e\entity,0,0,e\spz End If If EntityPitch(e\entity,True)>0 TurnEntity e\entity,0,0,-e\spz End If TurnEntity e\entity,e\spx,0,0 End If If e\ca% = loopright ;LOOPRIGHT If EntityRoll(e\entity,True)<90 TurnEntity e\entity,0,0,e\spz End If If EntityRoll(e\entity,True)>90 TurnEntity e\entity,0,0,-e\spz End If If EntityPitch(e\entity,True)<0 TurnEntity e\entity,0,0,-e\spz End If If EntityPitch(e\entity,True)>0 TurnEntity e\entity,0,0,e\spz End If TurnEntity e\entity,e\spx,0,0 End If e\ct%=e\ct% - 1 If EntityY(e\entity,True) < 2000 And e\ca <> chase;CLIMB IF TOO LOW e\ca%=climb e\ct%=500 End If If e\ct% < 1 ;current action time expired so select new action e\ca%=Rnd(1,6) e\ct%=500 If e\ca% = chase e\ct% = 4000 End If If e\ca% = goback e\ct% = 1000 End If If e\ca% = climb ;any climb code here End If If e\ca% = base e\ct% = 4000 End If If e\ca% = loopleft Or e\ca% = loopright ;code here End If End If MoveEntity e\entity,0,0,e\spd enemycount = enemycount +1 Next End Function __________________________ However, when I comment out the following line from the MoveCamera function, ;EntityParent(fwdcam,0) the radar camera works but my camera movement is affected negatively. I can't understand how this line affects the radar as the radar camera is not parented to fwdcam nor vice versa. Can anyone help me with this one? Regards Johnno |
| ||
5 hours .. is that all ... I've spent days trying to trace 1 bug ;) I think you need to be more specific about what doesn't work though as I doubt anyone is going to trawl through all you're code without media and anything to try it with. I did notice that you're creating a camera every time you change the view. Not sure of the overheads here but doesn't seem like a good idea. Why not just reposition one camera to where you need it depending on the view? Also, the way you're doing the camera stuff with a load of pivots seems overcomplicated to me - maybe if you simplify this it would help. Stevie |
| ||
Woah.. thats complicated. :) Let me get this straight. You're using PVT as a pivot for the player. Then you're creating FWDCAM as a pivot for the camera, and parenting it to PVT. Then you're creating a camera and parenting it to FWDCAM which is parented to PVT? Try eliminating the FWDCAM pivot altogether (backup your code first, because it'll take too long to change back afterward). The camera should be following PVT anyway, so theres no need for ANOTHER pivot, its useless and can just introduce problems. if fowardcam is active, parent the camera to PVT and just set the child in the correct position relative to PVT to get the view you want. In addition, your forwardcam code is like this: Function MoveCamera() fparent=GetParent(fwdcam) EntityParent(fwdcam,pvt,True) dx#=EntityX(fwdcam) dy#=EntityY(fwdcam) dz#=EntityZ(fwdcam) r#=EntityRoll(fwdcam) p#=EntityPitch(fwdcam) y#=EntityYaw(fwdcam) If r# => 180 Then r# = r# - 360 If r# =< -180 Then r# = r# + 360 TurnEntity fwdcam,-p#,-y#,-r#*.03 TranslateEntity fwdcam,-dx*.1,-dy*.1,-(dz+10)*.5 EntityParent(fwdcam,0) End Function In the beginning you use fpparent to find the parent of fwdcam. Why is this? Because you just set the parent for fwdcam to 0 without using fpparent in the rest of the code there. Is there something you meant to do with that information and forgot to? +BlackD |
| ||
Try using an EntityOrder with a larger number than 0, for your radar camera, this might do the trick, although I haven't looked at your code. |
| ||
Check out the current Source for Galactic so far there is a multiple camera-view option which alternates between: in-cockpit camera rear-view cam, view from just behind, external, rotational - mouse controlled view The radar has a separate camera render visible when in cockpitview mode. Although it's quite messy and maybe not so clear to discern if you've only had 2 weeks worth of Blitzing ;-) |
| ||
Without reading through your code...you can create a bunch of cameras then show/hide the ones you're interested in or not. If you want a smaller camera viewport rendered over your main camera do something like hideentity littlecam showentity maincam renderworld showentity littlecam hideentity maincam renderworld flip This will render your main scene then render your extra cam afterwards (ie overlay it) then flip the backbuffer. Also look at using the {codebox}{/codebox} tags (with [] instead of {}) to maintain your code formatting. The code you've posted looks horrible due to lack of indenting. |
| ||
Thanks everyone for your replies. I think my code is a bit all over the place. I've got a lot to learn. The following line; has fixed the problem. As for the reason I've changed cameras this way... It was the first way I tried it and it worked. As I said I've got a lot to learn :) Thanks for your help. Regards Johnno |