Jump to content

3rd person movement


ZioRed
 Share

Recommended Posts

The game I'm working on (an RPG) is based on 3rd person camera view, but it seems I'm doing something wrong (in this example I'm using LEO):

 

// ...
Controller player;
player.Create();
player.SetType(1);
player.SetMass(1);
player.SetPosition(Vec3(4.04601192,2.42112565,-16.9856968), GLOBAL);
player.SetRotation(Vec3(7.50344181,163.239944,-2.95039424), GLOBAL);

Model body("abstract::soldier.gmf");
body.SetType(1);
body.SetMass(1);
body.SetPosition(Vec3(4.04601192,2.42112565,-16.9856968), GLOBAL);
body.SetRotation(Vec3(7.50344181,163.239944,-2.95039424), GLOBAL);

// ...
while( !Keyboard::I****(KEY_ESCAPE) && !engine.IsTerminated() ) {

move = KeyDown(KEY_W)-KeyDown(KEY_S);
strafe = KeyDown(KEY_D)-KeyDown(KEY_A);
// ...
player.Update(0.0, move * 2.5, strafe, jump, 500.0f, 1, crouch);
TVec3 playerpos = player.GetPosition();
body.SetPosition(playerpos);	
// ...
engine.Flip();
}
return engine.Free();

 

The problem is that the character model (the soldier) does not move when I press the WASD keys but it's ever moving all around (even if I don't press any key):

 

I have tried in a fresh project the CreateController example on wiki but it didn't work for me (I'm using LE 2.31), the cylinder didn't move at all.

 

PS: I don't know if I need a Controller or it's enough simply a Model to position when key pressed (this game will not have a 1st person camera view), I am really newbie both in LE and in game development (I've been a senior "management software" developer till now).

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

Your player model collides with the controller:

body.SetPosition(playerpos);

Set the player model to type 0, so it doesn't collide with anything.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Your player model collides with the controller:

body.SetPosition(playerpos);

Set the player model to type 0, so it doesn't collide with anything.

mmh.. didn't work, I tried SetType(0) and SetType(3) (that is no collisions w/ other entities) but the model still seems to collide w/ something (if I comment the SetMass on player controller than the model seems to follow cylindrical collisions). :)

 

I generally just use LoadMesh() instead of LoadModel() since the character controller is acting as your physics body.

That works perfectly, I think to use Mesh instead of Model too, thanks. :lol:

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

I generally just use LoadMesh() instead of LoadModel() since the character controller is acting as your physics body.

I'm following this way, but now I'm trying to figure out how to rotate the controller when the body mesh is turned in a direction.

 

This is my scenario: when I hold down the right mouse button my body mesh turn into the inverted camera direction but of course the controller will not. This is the code (before framework update method call):

if (Mouse::IsDown(RIGHT))
{
body.SetRotation(camrotation);
body.Turn(Vec3(0, 180, 0));
}

I have tried to call the following line both just inside that "if" and after the framwork Update method but without luck:

player.SetRotation(body.GetRotation());

What happens is the mesh flickering or turning from left to right position. Any thoughts or suggestion?

?? FRANCESCO CROCETTI ??

http://skaredcreations.com

Link to comment
Share on other sites

What you would do is rotate the character mesh (I generally have a pivot there that I rotate and move along with the mesh though). You should then be able to get the mesh/pivot Y rotation value and apply that to the UpdateController() rotation parameter. That will rotate the controller body correctly and keep physics working. Now both your character mesh and controller will be pointing in the right direction.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...