Camera Problem!

Blitz3D Forums/Blitz3D Programming/Camera Problem!

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here's some code to do it. It's uses up and down arrow keys to move the camera :)

Graphics3D 800,600
SetBuffer BackBuffer()

Global camera=CreateCamera()

Global light=CreateLight()

Global cube=CreateCube()

EntityParent camera,cube

PositionEntity camera,0,2,-5

Global cube1=CreateCube(); cube so you can see movement
EntityColor cube1,100,100,255
PositionEntity cube1,-1,0,5


While Not KeyHit(1)

	If KeyDown(200) Then movecamera(0.1)
	If KeyDown(208) Then movecamera(-0.1)
	
	
	UpdateWorld
	RenderWorld
	Text 0,0,"cam height="+EntityY(camera,True)
	Flip
Wend


Function movecamera(value#)

	RotateEntity camera,0,EntityYaw(camera),EntityRoll(camera)
	
	If Abs(EntityDistance(camera,cube))>0.5 And Abs(EntityDistance(camera,cube))<10 Then;ensure it's inside limits
		MoveEntity camera,0,0,value; move camera
	End If
	If Abs(EntityDistance(camera,cube))<3 Or Abs(EntityDistance(camera,cube))>10 Then; make sure camera stays within limits
		MoveEntity camera,0,0,-value; move camera back to previous location
	End If
	PointEntity camera,cube

End Function