View Snippet
By RUCCUS
<UPDATE> See the 4TH Post for an update on the 1st person view, this one still works but the one in Post 4 is easier to incorperate and involves less lag...I think.
</UPDATE>
Pretty self explanatory, basically a limb is added behind the object, hidden and the camera is located at that limb. Then the camera points to the main object. Thus 3rd person view (explaining 3rd since it seems to be the most common problem). If you need any help just ask.
Haven't seen it done like this before so just giving another idea out to the community.
`````````````````````````````````````````````````````````````````
`1st, 2nd and 3rd Person View Snippet V1 `
`By RUCCUS of The Game Creators `
`````````````````````````````````````````````````````````````````
`This snippet is free for use. No royalties or credit is `
`required however a mention of my name is always appretiated. `
`This snippet has only been tested with DarkBASIC Proffesional `
`thus it hasn't been confirmed that it works with DarkBASIC `
`Classic, though it most likely will work. If you do test this `
`with DBC and everything works fine, please inform me either on `
`the forums or by emailing me at [email protected]. `
`````````````````````````````````````````````````````````````````
`If you have any questions on how to manipulate and tweek the `
`code to work for your game (thought you should just be able to `
`plug it right into your code) email me once again at `
`[email protected]. `
`````````````````````````````````````````````````````````````````
`SETUP GAME
SYNC ON:SYNC RATE 0
AUTOCAM OFF:HIDE MOUSE
`DEFINE VARIABLES
MODE#=1`Represents the starting view mode setting. 1 = First Person, 2 = Second Person, 3 = 3rd Person
`CREATE OBJECTS
MAKE OBJECT CUBE 1,20`Make our character
MAKE OBJECT CUBE 2,30`Make another object so we can see that we're moving
POSITION OBJECT 2,0,0,40`Position the second object away from the user
`CREATE LIMBS
` - 3rd Person View Limb
MAKE OBJECT CUBE 5000,.1`Create a "dummy" object
MAKE MESH FROM OBJECT 5000,1`Create a mesh or "blue print" of the dummy object
DELETE OBJECT 5000`Delete the dummy object to reduce lag, it's not needed any more
ADD LIMB 1,1,5000`Create a limb from the mesh "blue print" and then add it to object 1, our character
OFFSET LIMB 1,1,0,30,-70`Offset or Position the limb far behind our character (object 1) and slightly in the air
HIDE LIMB 1,1`Hide the limb so we can't see it, it's not supposed to be seen
` - 1st Person View Limb
MAKE OBJECT CUBE 6000,.1`Create a "dummy" object
MAKE MESH FROM OBJECT 6000,1`Create a mesh or "blue print" of the dummy object
DELETE OBJECT 6000`Delete the dummy object to reduce lag, it's not needed any more
ADD LIMB 1,2,6000`Create a limb from the mesh "blue print" and then add it to object 1, our character
OFFSET LIMB 1,2,0,5,0`Offset or Position the limb right where our character is, and a tiny bit upwards
HIDE LIMB 1,2`Hide the limb so we can't see it, it's not supposed to be seen
` - 1st Person View TARGET Limb
MAKE OBJECT CUBE 7000,.1`Create a "dummy" object
MAKE MESH FROM OBJECT 7000,1`Create a mesh or "blue print" of the dummy object
DELETE OBJECT 7000`Delete the dummy object to reduce lag, it's not needed any more
ADD LIMB 1,3,7000`Delete the dummy object to reduce lag, it's not needed any more
OFFSET LIMB 1,3,0,5,15`Offset or Position the limb infront if the character, so we have something to point our camera at, to make sure we're always looking forwards
HIDE LIMB 1,3`Hide the limb so we can't see it, it's not supposed to be seen
`LOOP OF EVENTS
DO` Do, this starts our Loop of what we want to be checked and completed over and over
`ON SCREEN INFORMATION
` Display some info like the controls and different views, and a title on our screen
TEXT 240,0, "PLAYER VIEW TUTORIAL"
TEXT 275,15,"BY RUCCUS"
TEXT 0,25,"CONTROLS:"
TEXT 0,35,"[]LEFT KEY : TURN LEFT"
TEXT 0,45,"[]RIGHT KEY : TURN RIGHT"
TEXT 0,55,"[]UP KEY : MOVE FORWARD"
TEXT 0,65,"[]DOWN KEY : MOVE DOWNWARD"
TEXT 0,80,"MODES:"
TEXT 0,90,"[] -1- : 1ST PERSON VIEW"
TEXT 0,100,"[] -2- : 2ND PERSON VIEW"
TEXT 0,110,"[] -3- : 3RD PERSON VIEW"
`DEFINE/STORE LIMB INFORMATION
LIMBX1#=LIMB POSITION X(1,1)`Store the 3rd Person Limb's X coordinate
LIMBY1#=LIMB POSITION Y(1,1)`Store the 3rd Person Limb's Y coordinate
LIMBZ1#=LIMB POSITION Z(1,1)`Store the 3rd Person Limb's Z coordinate
LIMBX2#=LIMB POSITION X(1,2)`Store the 1st Person Limb's X coordinate
LIMBY2#=LIMB POSITION Y(1,2)`Store the 1st Person Limb's Y coordinate
LIMBZ2#=LIMB POSITION Z(1,2)`Store the 1st Person Limb's Z coordinate
LIMBX3#=LIMB POSITION X(1,3)`Store the 1st Person TARGET Limb's X coordinate
LIMBY3#=LIMB POSITION Y(1,3)`Store the 1st Person TARGET Limb's Y coordinate
LIMBZ3#=LIMB POSITION Z(1,3)`Store the 1st Person TARGET Limb's Z coordinate
`1ST PERSON MODE
IF MODE#=1`If the Mode variable equals 1
POSITION CAMERA LIMBX2#,LIMBY2#,LIMBZ2#`Position the camera at the 1St Person Limb's coordinates
POINT CAMERA LIMBX3#,LIMBY3#,LIMBZ3#`Aim the camera at the TARGET Limb, so we are always looking forwards
ENDIF`End the if statement
`2ND PERSON MODE
IF MODE#=2`If the Mode variable equals 2
POSITION CAMERA LIMBX2#,LIMBY2#+OBJECT SIZE(1)*3,LIMBZ2#`Position the camera at the 1st Person limb coordinates (no bother in creating another limb, we can use the 1st person limb for this mode) but, when it comes to the y coordinate, multiply the object's size by 3 and set the y to this. This way no matter what the camera is always above the object.
POINT CAMERA OBJECT POSITION X(1),OBJECT POSITION Y(1),OBJECT POSITION Z(1)`Aim the camera at the character object, so we can still see it. Try taking this out and seeing what happens.
ENDIF`End the if statement
`3RD PERSON MODE
IF MODE#=3`If the Mode variable equals 3
POSITION CAMERA LIMBX1#,LIMBY1#,LIMBZ1#`Position the camera at the 3rd Person Limb coordinates
POINT CAMERA OBJECT POSITION X(1),OBJECT POSITION Y(1),OBJECT POSITION Z(1)`Point the camera at the character object so we can always see it
ENDIF`End the if statement
`CONTROLS: Moving forward and backward
IF UPKEY()=1 THEN MOVE OBJECT 1,1`If the upkey is pressed, move the character forward at 3 units per press
IF DOWNKEY()=1 THEN MOVE OBJECT 1,-1`If the upkey is pressed, move the character backward at 3 units per press
`CONTROLS: Turning left and right
ANGLEY# = OBJECT ANGLE Y(1)`Store object 1's Y angle, we need it for the next part of code
IF LEFTKEY()=1 THEN YROTATE OBJECT 1,WRAPVALUE(ANGLEY#-1)`If the left key is pressed then rotate object 1 on it's y axis, use the wrap value command to reset the value if it's over 360 or below 0, and rotate the object at a rate of it's Y Angle + 3 Units per press
IF RIGHTKEY()=1 THEN YROTATE OBJECT 1,WRAPVALUE(ANGLEY#+1)`If the right key is pressed then rotate object 1 on it's y axis, use the wrap value command to reset the value if it's over 360 or below 0, and rotate the object at a rate of it's Y Angle - 3 Units per press
`CONTROLS: Mode Switching
IF KEYSTATE(2)=1 THEN MODE#=1`If 1 is pressed, set the Mode variable to 1
IF KEYSTATE(3)=1 THEN MODE#=2`If 2 is pressed, set the Mode variable to 2
IF KEYSTATE(4)=1 THEN MODE#=3`If 3 is pressed, set the Mode variable to 3
`LOOP ENDING
SYNC
LOOP
-
RUCCUS