inteligent cameras
Blitz3D Forums/Blitz3D Beginners Area/inteligent cameras
| ||
if i may...another question does any one know of any easy to understand code on camera movement, i tried just parenting it to the character..but it looks ..well crap for want of a better word, i want it to move with like a pause so when the kid turns you get to see him side on then it slowly goes behind, i have tried to understand the castle demo but it lost me,damn i wish they had put some documentation in that code..its about all i have for reference quick and dirty test needs major tweaking (temp graphics) real raw stuff...but i learnt a lot http://www.btinternet.com/~coloured.pixels/Kid_0.2.zip |
| ||
Hmmm, set up a variable: cameradelay#=0 for storing how much the camera is turned relative to being behind the kid, so if you turn the kid: kidrotation#=kidrotation#+5, then you turn cameradelay in the opposite direction: cameradelay#=cameradelay#-5. Once every loop you adjust it to go slightly closer to behind the kid: If cameradelay#<1 and cameradelay#>-1 Then cameradelay=0 Else if cameradelay#>0 Then cameradelay#=cameradelay#-1 Else cameradelay#=cameradelay#+1 End If Then there is the positioning of the camera: PositionEntity camera,EntityX(kid)-Sin(kidrotation#+cameradelay#)*10,EntityY(kid)+4,EntityZ(kid)-Cos(kidrotation#+cameradelay#)*10 RotateEntity camera,kidrotation#+cameradelay#,-20,0 I havn't tested the last piece, but it should work, you probably need to alter some of the factors to make it just like you want it. |
| ||
cheers eBusiness..i will give it a go (first i will try and usderstand it) |
| ||
Ehrm, wait a little with trying to understand it, I'll bring an update. Edit: Dude it looked funny with the castle demo, I wasn't quite able to remember what pitch, yaw and roll meant. Anyway, here you go: If cameradelay#<.3 And cameradelay#>-.3 Then cameradelay=0 Else If cameradelay#>0 Then cameradelay#=cameradelay#*.96-.3 Else cameradelay#=cameradelay#*.96+.3 End If PositionEntity camera,EntityX(kid)+Sin(EntityYaw(kid)+cameradelay#)*10,EntityY(kid)+8,EntityZ(kid)-Cos(EntityYaw(kid)+cameradelay#)*10 RotateEntity camera,40,EntityYaw(kid)+cameradelay#,0 If you want the camera to be more "unbound" then I think I have a solution for it. |
| ||
Yo, tiler. Try this out. Arrow keys to move the guy. Most of the code sets up the scene :)Graphics3D 800,600 SetBuffer BackBuffer() Global camera=CreateCamera() PositionEntity camera,0,0,-10 Global light=CreateLight() Global camera_distance=10; set distance camera will be Global camera_speed#=30; speed the camera moves at. Lower values will move the camera faster! Global player=CreateSphere() ScaleEntity player,0.5,0.5,1 Global player_pivot=CreatePivot(player); pivot the camera uses for smooth moving PositionEntity player_pivot,0,5,-camera_distance ; position the point you want the camera to be at ; create some cube to base movement on Dim cube(10) For loop=0 To 10 cube(loop)=CreateCube() PositionEntity cube(loop),Rnd(-10,10),0,Rnd(-10,10) EntityColor cube(loop),Rnd(10,110),Rnd(10,110),210 Next While Not KeyHit(1) If KeyDown(200) Then MoveEntity player,0,0,0.1 If KeyDown(208) Then MoveEntity player,0,0,-0.1 If KeyDown(203) Then TurnEntity player,0,1,0 If KeyDown(205) Then TurnEntity player,0,-1,0 update_camera(camera,player_pivot,player,camera_speed) ; update the camera UpdateWorld RenderWorld Flip Wend End Function update_camera(cam,pivot,player,speed) PointEntity cam,pivot If EntityDistance#(cam,pivot) >0.5 Then MoveEntity cam,0,0,EntityDistance(cam,pivot)/speed End If PointEntity cam,player End Function |
| ||
cheers guys...much appreciated |