3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: 3rd Person Char.  (Read 1104 times)

« on: December 23, 2010, 04:24:29 AM »
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.
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.

jestermon

« Reply #1 on: December 24, 2010, 03:02:29 AM »
After looking through your code, I realized that you made the same mistake that I made when I started using 3D Rad. Namely getting confused between moving objects with maths, and with built in forces and objects. It is a very common mistake, and it takes a while to get into the correct mindeset to use 3D Rad properly.

You can use maths to move skinmeshes as much as you like, but try to avoid moving rigidbodies with maths, unless you have a very good reason to do so, such as moving random platforms for a platform type game.

When it comes to moving rigidbodies, it's best to use forces and built in objects, such the character object, since they are designed to work perfectly with the physics collision engines.

I was not sure of what you wanted to do, so I put together a demo that replicates the movement that I picked up in your project, namely walking in 4 possible directions, as would be used in a �brick pushing� type of game. The are many other ways to control character movement, but using a target to do so, is not only the easiest way, but also gives you great control, because you can control the target with ease.

If you look at the demo I made, it does Not need elaborate maths to work. What it does is take the location of the character rigidbody, and add or subtract an x or z (axis) value from it, and keep the target there t force the character to move in that direction. All I do is play with the target, and let the Character object do all the rest of the work. I Let the physics take care of itself.

Take a look at how the objects are linked, and note that the keys in the character are deactivated, so that they don't control the character directly. You can remove the target, and activate the keys, and it will also control the character just as well. The target method allows you to add all sorts of other stuff,  such as following and enemy, or going where I wish by programming the target, so I usually go that way.
I will leave you to experiment further.

Have fun.

PS: Move with Left, Right, Up, Down.  Space to stop
« Last Edit: December 24, 2010, 03:13:05 AM by jestermon »
« Reply #2 on: December 25, 2010, 06:09:09 AM »
Many thanks jestermon. Ill look into your project to see if I can come up with anything interesting. Im very sorry for not explaining at what I was trying to get at earlier. I wanted to basically create a character object that has a jump that works. Ive tried using the character object attached to a velocity pointed straight up. For the most part it does what it supposed to do make the character go up but its buggy for me. You press spacebar multiple times and it does a super jump. And you also cant controll your character in air. So my attempt was to use script for movement and jumping too. Ill look into your project to see if I can make it work out. Btw, many thanks to you for your time and I hope you have a very Merry Christmas  ;)
Pages: [1]