3rd Person View w/ Rotating and Zooming Snippet
DBP - May work in DBC aswell
`3rd Person View w/ Zooming
`Created by RUCCUS, Thursday October 20th, 2005
`For help contact me at ruccus@ruccus.net or add
`Ask-RUCCUS@hotmail.com and I'll help you on MSN if I can.
SYNC ON:SYNC RATE 0:AUTOCAM OFF:HIDE MOUSE
MAKE OBJECT BOX 1,30,100,10
MAKE OBJECT TRIANGLE 2,0,0,0,0,0,0,0,0,0
MAKE MESH FROM OBJECT 1,2
ADD LIMB 2,1,1
OFFSET LIMB 2,1,0,200,-500
HIDE LIMB 2,1
MAKE OBJECT CUBE 3,200
POSITION OBJECT 3,0,0,300
OFFSET#=-500
DO
INC OFFSET#,MOUSEMOVEZ()
IF OFFSET#<-500 THEN OFFSET#=-500
IF OFFSET#>-100 THEN OFFSET#=-100
OFFSET LIMB 2,1,0,200,OFFSET#
X#=OBJECT POSITION X(1)
Y#=OBJECT POSITION Y(1)
Z#=OBJECT POSITION Z(1)
POSITION OBJECT 2,X#,Y#,Z#
POSITION CAMERA LIMB POSITION X(2,1),LIMB POSITION Y(2,1),LIMB POSITION Z(2,1)
POINT CAMERA X#,Y#,Z#
IF KEYSTATE(17)=1 THEN MOVE OBJECT 1,1
IF KEYSTATE(31)=1 THEN MOVE OBJECT 1,-1
IF KEYSTATE(30)=1 THEN MOVE OBJECT LEFT 1,1
IF KEYSTATE(32)=1 THEN MOVE OBJECT RIGHT 1,1
CAMY#=CAMY#+MOUSEMOVEX()*.1
CAMX#=CAMX#+MOUSEMOVEY()*.1
IF CAMX#>90 AND CAMX#<135 THEN CAMX#=90
IF CAMX#>270 AND CAMX#<225 THEN CAMX#=90
YROTATE OBJECT 1,CAMY#
YROTATE OBJECT 2,CAMY#
XROTATE OBJECT 2,CAMX#
SYNC
LOOP
Breakdown:
Object 2 is a dummy object, it has a limb offset at the starting position you want the camera at. Every loop the camera is positioned at this limb's coordinates and pointed to object 1. Also, every limb the dummy object 2 is positioned at object 1's coordinates, now the camera will follow the user as they move.
Next we use the basic mouse looking code used in a lot of FPSs nowadays on DBP, and alter it a bit. We only rotate object 1 on the y axis and not the x axis so the user can't fly around, and then we rotate object 2 on yhe y and x axis so the user can look in all directions as the mouse moves.
Finally, we offset the limb from object 2 on the z axis by OFFSET#, OFFSET# changes depending on MOUSEMOVEZ(), so as the user scrolls the limb offsets closer and further away from the object, causing the camera to go with it, giving a zooming ability. There's limits invluced aswell, if OFFSET is less than -500 then it stops zooming out, and if it's greater than -100 then it stops zooming in. Alter the limits and the amountt he camera zooms in, aswell as what axis are changed for different effects. It might be a good idea to alter the Y offset of the limb aswell.
Controls:
- WSAD movement
- Move Mouse to look around
- Use scroll button to zoom in/out
Hope it helps, goodluck.