Hey guys I usually dont ever ask for help but this has been bothering me for the past few days. Ive been trying to work on a new Character Object. I dont know if an easier method has been found yet but this is what I've been able to gather. I've combined jestermon's "Moving Mesh" Forward script found here http://www.3drad.com/forum/index.php?topic=5373.0 with chebob69's "Advanced Character Movement v2.0" found here http://www.3drad.com/forum/index.php?topic=3605.0. Now the problem I've encountered after creating the character, is when the character rigidbody touches another rigidbody the character stars moving backwards all on its own sort of doing the "Moonwalk". Ive tried doing my fair share of work in the 3DRad Script Object Reference for some help but Im stumped here. It would really help to have a fresh pair of eyes on this to help me out. Heres my Character Controlled script.
Very special thanks to jestermon and chebob69 and everyone else here at the 3DRad forums helping everyone out. Im going to school to be a 3D Artist and creating games has been a dream of mine. Thanks to everyone and Fernando for making 3DRad amazing.
Code: [Select]
///////////Chebob69 and Jestermon's combined code////////////////////////
/////////////////////Character Movement//////////////////////////////////
Quaternion CameraOrientation;
Quaternion CharacterOrientation;
Quaternion L;
Quaternion R;
Quaternion D;
Quaternion U;
Quaternion UR;
Quaternion UL;
Quaternion DR;
Quaternion DL;
Vector3 CharacterLocation,CameraLocation;
float Radius;
int MESH = OBJ_0; //set MESH = OBJ_x where x is your skinmsh ID
//----------------------------------------
Vector3 moveTo(Vector3 v1, Vector3 v2, float speed)
{
Vector3 Vresult,vv;
vv = v2-v1;
iVectorLengthSet(Vresult,vv,speed);
Vresult += v1;
return Vresult;
}
//-------------------------------------
void Main()
{
/////JUMP///////////
if (iKeyDown(iKeyCode("DIK_SPACE")))
{
iObjectStart(OBJ_66);
}
//////END JUMP/////
//Stage 2 - Initialising
if (iInitializing())
{
iMouseLookSet(0,0);
iObjectLocation(OBJ_22,CameraLocation);
iObjectLocation(OBJ_0,CharacterLocation);
Radius=iVectorLength(CameraLocation-CharacterLocation);
}
//Stage 3 - Dynamic player direction
iQuaternionFromEulerAngles(L,0,270+iMouseLookY(),0,"xyz");
iQuaternionFromEulerAngles(R,0,90+iMouseLookY(),0,"xyz");
iQuaternionFromEulerAngles(D,0,180+iMouseLookY(),0,"xyz");
iQuaternionFromEulerAngles(U,0,0+iMouseLookY(),0,"xyz");
iQuaternionFromEulerAngles(UR,0,45+iMouseLookY(),0,"xyz");
iQuaternionFromEulerAngles(UL,0,315+iMouseLookY(),0,"xyz");
iQuaternionFromEulerAngles(DR,0,135+iMouseLookY(),0,"xyz");
iQuaternionFromEulerAngles(DL,0,225+iMouseLookY(),0,"xyz");
//Stage 4 - Adjust camera settings
if (iKeyDown(iKeyCode("DIK_RSHIFT")) && Radius>2)
{
Radius-=0.05;
}
if (iKeyDown(iKeyCode("DIK_RCONTROL")) && Radius<8)
{
Radius+=0.05;
}
//Stage 5 - Control character orientation
if (iKeyDown(iKeyCode("DIK_A")))
{
iObjectOrientationSet(OBJ_0,L);
CharacterOrientation=L;
}
if (iKeyDown(iKeyCode("DIK_D")))
{
iObjectOrientationSet(OBJ_0,R);
CharacterOrientation=R;
}
if (iKeyDown(iKeyCode("DIK_W")))
{
iObjectOrientationSet(OBJ_0,U);
CharacterOrientation=U;
}
if (iKeyDown(iKeyCode("DIK_S")))
{
iObjectOrientationSet(OBJ_0,D);
CharacterOrientation=D;
}
if (iKeyDown(iKeyCode("DIK_S")) && iKeyDown(iKeyCode("DIK_D")))
{
iObjectOrientationSet(OBJ_0,DR);
CharacterOrientation=DR;
}
if (iKeyDown(iKeyCode("DIK_S")) && iKeyDown(iKeyCode("DIK_A")))
{
iObjectOrientationSet(OBJ_0,DL);
CharacterOrientation=DL;
}
if (iKeyDown(iKeyCode("DIK_W")) && iKeyDown(iKeyCode("DIK_A")))
{
iObjectOrientationSet(OBJ_0,UL);
CharacterOrientation=UL;
}
if (iKeyDown(iKeyCode("DIK_W")) && iKeyDown(iKeyCode("DIK_D")))
{
iObjectOrientationSet(OBJ_0,UR);
CharacterOrientation=UR;
}
//*********************************MOVEMENT***************************************
if (iKeyDown(iKeyCode("DIK_S")) || iKeyDown(iKeyCode("DIK_W")) || iKeyDown(iKeyCode("DIK_A")) || iKeyDown(iKeyCode("DIK_D")))
{
///Moving Foward
Vector3 meshLocation; //the location vector of your mesh
Vector3 meshDirection; //the direction vector of your mesh
Vector3 ZERO = Vector3(0,0,1); //a z = forward direction vector
float speed = 0.25; //the speed we want to move the mesh
Quaternion meshOrientation; //the orientation of your mesh
iObjectLocation(MESH,meshLocation); //get the location of your mesh
iObjectOrientation(MESH,meshOrientation); //get the orientation of your mesh
//We rotate our z-forward and get the mesh direction vector
iVectorRotate(meshDirection,ZERO,meshOrientation);
//We change the direction vector to a speed and direction vector
iVectorLengthSet(meshDirection,meshDirection,speed);
//We add the speed-direction vector to the mesh location vector to move it
meshLocation += meshDirection;
//We now translate (move) the mesh to its new location
iObjectLocationSet(MESH,meshLocation);
}
//---------------------------------
//****************END MOVEMENT********************************************************
//Stage 6 - Determine camera location
iObjectLocation(OBJ_0,CharacterLocation);
iMouseLookYRangeSet(50,-10);
CameraLocation.x=CharacterLocation.x+Radius*iFloatSin(-iMouseLookY())*iFloatSin(90-iMouseLookX());
CameraLocation.y=CharacterLocation.y+2+Radius*iFloatCos(90-iMouseLookX());
CameraLocation.z=CharacterLocation.z+Radius*-iFloatCos(iMouseLookY())*iFloatSin(90-iMouseLookX());
iObjectLocationSet(OBJ_22,CameraLocation);
iQuaternionFromEulerAngles(CameraOrientation,iMouseLookX(),iMouseLookY(),0,"xyz");
iObjectOrientationSet(OBJ_22,CameraOrientation);
iObjectOrientationSet(OBJ_0,CharacterOrientation);
;
}
Very special thanks to jestermon and chebob69 and everyone else here at the 3DRad forums helping everyone out. Im going to school to be a 3D Artist and creating games has been a dream of mine. Thanks to everyone and Fernando for making 3DRad amazing.