TGC Codebase Backup



Easy Following camera movement by Seppuku Arts

2nd Feb 2006 18:10
Summary

This is an easy piece of code to get your camera to follow your 3D object



Description

This is an easy piece of code to get your camera to follow your 3D object. Uses simple variables and commands.

This will be updated with a new one with camera collisions so that the camera doesn't walk through walls



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    cls
sync on
sync rate 30
`just set up a scene
make object cube 1,100
make matrix 1,10000,10000,30,30

`give the camera a position
position camera 100,100,100
`this is just an important variable
o# = 0
do
`move the object
if upkey()=1 then move object 1,10
if downkey()=1 then move object 1,-5
if leftkey()=1 then turn object left 1,3
if rightkey()=1 then turn object right 1,3
`record object position
x# = object position x(1)
y# = object position y(1)
z# = object position z(1)
`record camera x and z positions
cx# = camera position x()
cz# = camera position z()
`point the camera at the object
point camera x#,y#,z#
`Lets make sure the camera has a retricted y position (200 above the object)
position camera cx#, y#+200, cz#
`Lets make the camera follow the object
if upkey()=0 and downkey()= 0 then inc o#,1
if o# > 10 then o# = 10
if o# < 10 then move camera 10
if upkey()=1 or downkey()=1 then o# = 0

`Hope it helps

sync
loop