Hello, sorry for yet another nub like post. But I was wondering if someone could point me in the direction of a good tutorial, or even a basic code script that explains how to make a 3rd person movement? I have written some code, but its only front back, strafe right and strafe left and I dont really understand the logic behind the strafe left and right considering I just got it off of a darkbasic tutorial. What i need is so that you can look with the camera, and when you hit the up arrow the character will move in that direction.
Here is what I have
// Dark GDK - The Game Creators - www.thegamecreators.com
// the wizard has created a very simple project that uses Dark GDK
// it contains the basic code for a GDK application
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include "SC_Collision.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
//Start reading Sparkys Collision
SC_Start ();
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
//Set our directory to the media folder
SetCurrentDirectory ("media");
dbLoadObject ( "universe.dbo", 1);
dbSetObjectLight (1, 0);
//Load our textures
dbLoadImage ("Metal_Plates_T.bmp",1);
dbLoadImage ("gothic_T.bmp",2);
//Load our skybox
dbLoadObject ("skybox2.x",2 );
dbSetObjectLight (2,0);
dbSetObjectTexture (2,3,2);
dbScaleObject (2,5000,5000,5000);
//Make our character (sphere)
dbMakeObjectSphere (3, 25);
dbPositionObject (3, 434, 42, -525);
//Declare variables
float Xf;
float Zf;
float Xtestf;
float Ztestf;
int boxhealth = 100;
//Make our boxes
dbMakeObjectCube (4,50);
dbPositionObject (4, 434,42, -470);
//Texture our Objects
dbTextureObject (3,1);
dbTextureObject (4,2);
//Position the camera
dbMakeCamera (1);
dbPositionCamera (1,434,42,-517);
//Turn on Our Collision
SC_SetupObject (1,0,0);
SC_SetupObject (3,0,1);
SC_SetupObject (4,0,2);
SC_SetObjectCollisionOn (1);
SC_SetObjectCollisionOn (3);
SC_SetObjectCollisionOn (4);
float AYf = 0.0;
// our main loop
while ( LoopGDK ( ) )
{
Xtestf = dbObjectPositionX(3);
Ztestf = dbObjectPositionZ(3);
AYf = dbObjectAngleY (3);
Xf = dbObjectPositionX (3);
Zf = dbObjectPositionZ (3);
//Stores the Y coordinate of the sphere
//Rotates the sphere if keys are pressed
//Moves the sphere if keys are pressed
if (dbUpKey()) dbMoveObject (3,5);
if (dbDownKey()) dbMoveObject (3,-5);
//This strafes the sphere
if (dbLeftKey()) {
Ztestf = dbNewZValue (Zf,dbWrapValue(dbObjectAngleY(3)-90),10);
Xtestf = dbNewXValue (Xf,dbWrapValue(dbObjectAngleY(3)-90),10);
dbPositionObject (3,Xtestf,42,Ztestf);
}
if (dbRightKey()) {
Ztestf = dbNewZValue (Zf,dbWrapValue(dbObjectAngleY(3)+90),10);
Xtestf = dbNewXValue (Xf,dbWrapValue(dbObjectAngleY(3)+90),10);
dbPositionObject (3,Xtestf,42,Ztestf);
}
//store the X Z positions of the object
//Object Collision Detection
if (SC_ObjectCollision (3,4)){
dbPositionObject(3,Xf,42,Zf);
}
if (SC_ObjectCollision (3,0)) {
dbPositionObject(3,Xf,42,Zf);
}
//get the coordinates behind the sphere for camera positioning
float cZf = dbNewZValue(Zf, AYf - 180,100);
float cXf = dbNewXValue(Xf, AYf - 180,100);
//Position the camera behind the sphere
dbPositionCamera(1,cXf, 50, cZf);
//Point the camera at the sphere
dbPointCamera(1,Xf,50,Zf);
// update the screen
dbSync ( );
}
// return back to windows
return;
}
Also, in there I have started the sparkys collision, but it doesnt work the way that db's collision works. How do you know when collision is detected. Like, if you wanted to know if collision happened between two objects with db the code would be
if (dbObjectCollision(first object,second object) {
dbpositionobject (first object, x,y,z);
}
How do you accomplish the same task with sparkys?
typos...