making a 'smart' camera
Blitz3D Forums/Blitz3D Programming/making a 'smart' camera
| ||
hi all, i was wondering if anyone could give me pointers on how to make a 'smart' camera to my platformer game as i have no idea even how to start thanks |
| ||
Well it depends on how "smart" you want your camera to be (ie. what exactly you want it to do.) For simply keeping an unobstructed view between the camera and player there are tricks involving the built-in collision detection system to move the camera: detect collisions between the camera and level, then move the camera in to keep a constant distance from the player, and point the camera at the player every frame. For a smarter camera than that (eg. one which moves to ideal camera angles for given areas of a level) you will pretty much need to code AI to control the camera, basically writing a virtual cameraman which moves the camera around. A waypoint system is helpful here; define waypoints (ie. good camera spots) throughout the level and then have the camera drift from waypoint to waypoint as the player moves through the level. Either way you check the player's location every frame after UpdateWorld (so that collision detection will have already happened) and then have some sort of algorithm which places the camera based on the player's location. There are some samples in the Code Archives and which came with Blitz3D which demonstrate 3rd person camera control. |
| ||
Marks Castle demo seems to be a popular choice. Also, Rob Pearmains Mario Camera Control is worth a look. |
| ||
here's one I made, works really nice, and very simple.. if you want, you can use sliding collision for the camera to keep it from going through walls if you want. it's a lot like DB's "Set camera to follow command" the 'point' flag at the end will also point 'e1' at 'e2' if set to 1 Function Curve#(d#,c#,s#) If Abs(d-c)<0.01 Return d Else Return c+((d-c)/s) EndIf End Function Function followEntity(e1,e2,angle#,dist#,height#,speed#,point=0) x# = EntityX#(e2)+(Sin(angle#)*dist#): y# = EntityY#(e2)+height#: z# = EntityZ#(e2) - (Cos(angle#)*dist#) PositionEntity e1,curve#(x#,EntityX#(e1),speed#),curve#(y#,EntityY#(e1),speed#),curve#(z#,EntityZ#(e1),speed#) If point Then PointEntity e1,e2 End Function Use: followEntity(camera,player,entityyaw#(player),100,200,10,1) |