woot finally got this working
Jinzai i know you know what your talking about however the numbers that i use in this coding example work! and when i try to use the numbers you give me it does not....
the defining factor was your comment about the switch statement, i did as you advised and put the dbscancode into an int called key and then did case statements and put the looped animation into the WalkForward. Also note that the animation now only plays when the model is moving forward and stops when the model stops moving
I have provided my code (that compiles and gives the desired effect)
NOTE: i am tempted to switch the dbMouseClick to a similar format for (a: consistancy - & b: my research has revealsed that compilers generate more eficient code from them over if statements! - (i said i was new to this so please don't laugh)) so this has been a great learning experience!
void ThirdPerson (int obj)
{
my = dbMouseMoveY ( );
mx = dbMouseMoveX ( );
float x = dbCameraAngleX ();
float y = dbCameraAngleY ();
float z = dbCameraAngleZ ();
int key = dbScanCode ();
dbPositionCamera( dbObjectPositionX(obj),dbObjectPositionY(obj),dbObjectPositionZ(obj) );
dbRotateCamera( dbObjectAngleX(obj),dbObjectAngleY(obj),dbObjectAngleZ(obj) );
dbPitchCameraDown (40);
dbMoveCamera( -300 );
if (dbMouseClick() == 2)
{
dbPointCamera (x,y,z);
fCameraAngleX = dbWrapValue ( fCameraAngleX + my * 0.4f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + mx * 0.4f );
dbPositionMouse (dbScreenWidth() /2, dbScreenHeight() /2);
dbXRotateCamera (fCameraAngleX );
dbYRotateObject (obj, fCameraAngleY);
dbYRotateCamera (fCameraAngleY );
dbHideMouse();
}
else
{
dbPointCamera (dbObjectPositionX (obj),dbObjectPositionY (obj), dbObjectPositionZ(obj));
dbPitchCameraUp (20);
dbShowMouse();
}
//moves player & camera in direction they are facing
switch (key)
{
case (17):
WalkForwards (obj, 2.2f);
break;
case (31):
WalkBackwards (obj, -1.5f);
break;
default:
dbStopObject (obj);
break;
}
SC_UpdateObject (obj);
}
void WalkForwards (int obj,float Speed)
{
dbLoopObject ( obj, 0, 7000 );
dbSetObjectSpeed ( obj, 10000);
float littleRadius = 2.0f;
float oldx = dbObjectPositionX(obj);
float oldy = dbObjectPositionY(obj);
float oldz = dbObjectPositionZ(obj);
dbMoveObject (obj, Speed);
dbMoveCamera (Speed);
float x = dbObjectPositionX(obj);
float y = dbObjectPositionY(obj);
float z = dbObjectPositionZ(obj);
int collide = SC_SphereSlide( 0, oldx,oldy,oldz, x,y,z, littleRadius,obj );
if ( collide > 0 )
{
dbPositionObject( obj, SC_GetCollisionSlideX(),SC_GetCollisionSlideY(),SC_GetCollisionSlideZ() );
}
SC_UpdateObject( obj );
}
also just to make a note i have included a snipet from the "camera" tutorial that is included with the GDK
// load model and set properties
dbLoadObject ( "miko\miko.x", t );
dbSetObjectSpecular ( t, 0 );
dbXRotateObject ( t, 270 );
dbFixObjectPivot ( t );
// position based on which one we're creating
if ( t == 1 )
{
dbPositionObject ( t, 0, 0, 200 );
dbRotateObject ( t, 0, 180, 0 );
}
else
{
dbPositionObject ( t, 0, 0, -200 );
dbRotateObject ( t, 0, 180, 0 );
}
// start animation
dbLoopObject ( t, 0, 9000 );
dbSetObjectSpeed ( t, 500 );
this code is direct from the tutorial and un-edited (just wanted to show you why i was using such high values for the frames and speed!)
maybe we can continue this thread to figure out why the values are so high compared to the ones that work for you ?