TGC Codebase Backup



Following Camera Principles by MikeS

27th Feb 2004 16:06
Summary

Teaches how to make a following camera.



Description

Teaches how to make a following camera.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    ` This tutorial was created by Yellow -Mike- 2-26-04
` Although not necessary, it would be nice to be credited and
` notified at yellow1dbp@hotmail.com if this was used in a game
` Thanks, and I hope the tutorial helps.

` Welcome to the follow camera tutorial
` This will provide a basic tutorial on a following camera

`We first set the sync rate on and to a refresh rate of 60.
sync on : sync rate 60

`We make this matrix so it will give us a sense of direction in the program.
make matrix 1,1000,1000,10,10
`Now we make a cube, that will act as our main character.
make object cube 1,4
`This determines how fast our player will move. This line is not necessary,
`yet it helps us to tweak the speeds of our character to get it just right easily.
Object_Speed#=1

do `Initialize our loop

` "X" is the x position "1" is the object number
` and "#" tells the comiler we're working with numbers.
` These variables can be whatever you like, yet I like having a standard method that
` you can easily identify what each variable is for, and what object it applies to.
x1#=object position x(1)
y1#=object position y(1)
z1#=object position z(1)
` Same principles as above, yet the "a" stands for angle, "y" for the type of angle
` and the "#" tells the comiler we're working with numbers.
ay1#=object angle y(1)

`The reason we initialized the variables above, was so we could use the
`set camera to follow command. This lets the camera follow the object
`located at the x position(x1#), y position(y1#) and z position (z1#)
`We've also added the object angle y(ay#), so that when the object turns, the camera
`will re-adjust to the proper angle.

set camera to follow x1#,y1#,z1#,ay1#,5,5,1,1

`These two commands tell the object to move forward with the up and down keys.
`Again, you'll see the Object_Speed# variable, that determines how fast they go.
if upkey()=1 then move object 1,Object_Speed#
if downkey()=1 then move object 1,-Object_Speed#
`We use our object angle y(ay#) variable here to determine whether the object
`turns left or right.
if leftkey()=1 then rotate object 1,0,(ay1#)-1,0
if rightkey()=1 then rotate object 1,0,(ay1#)+1,0

sync `Refresh the screen
loop ` Loop the program

`You now have the basis of a follow cam tutorial.
`Hope this helped -Mike-
`Copyright(c) 2004 Curved Basic