character class ( rotating problem)

dupleg

29-04-2006 15:36:08

hi there. im trying to use the character class in my application. i have set up everything but not the rotation of the character. i used the tutorialFPS file in my application. i have got the 3rd person camera view, character moves through the mouse direction, but it does not rotate/face to the mouse direction. do i have to use torque or something? please give me some example or link. i want my character to face to the mousedirection. when i try to rotate to the mDirection, on every 180 degrees turn of mouse, character rotates 90 degree. how to fix this? i mean when my mouse rotates 180, character rotates 90 degree less than that. please help

betajaen

29-04-2006 18:55:12

Nope no torque is required!

The character class has a turn function for you. You should turn it to the angle that the character you want facing (obviously).

Looking at the source now (it's been a while), you have to specify the Quaternion.y angle of where you want the character to face. Not how many degrees to change.

As for an example, tutorial 311 is the only example we have. But to be honest I've never tried it with a 3rd person system yet. Perhaps working with a 1st person then switch to 3rd until you have the bugs sorted may be better. :D

dupleg

29-04-2006 22:44:01

im totally stuck with this crap. CAN u help me with some code betajaen? that will b very helpful. I hav tryd everything to solve this problem but no luck. plz help

betajaen

30-04-2006 01:10:22

Alright, explain it out step by step what you want.

dupleg

30-04-2006 14:18:53

this crap is really..... a crap.
in the source of the library, i saw that the "turn()" function only changes the mDirection quaternions .y property.that means we change the direction the force will be applied to. now i need to rotate the mController->getActor()->setWorldOrientation(toDisiredOrientation). that what i did. i set the orientation of the actor to the mDirection quaternion. it was the only .y property. but when i turn the camera 180 degree, the character rotates 90 to .y .

now what i want to do is to face the actor to the camera direction. i have got the 3rd person camera ok. it works properly with the character.

i want some function which will make the actor to face to the camDirection and the actor will move towards the way actor is faced.

could i make me clear? i dont know good english, sorry for that... :?

betajaen

30-04-2006 14:32:28

Right, could you attach a node to the character scenenode...then in that node offset the camera on how far away you want the camera.

Then to rotate the camera and the character just use turn.

dupleg

30-04-2006 16:43:17

i think i have already tried this thing. i could not understand what you r talking about.... but i have tried with another node with the lookAt() function to the camera direction. it works well. then i tried to get its y rotation, i mean orientation and apllied it to the mController->getActor()->setGlobalOrientation(), then it became shit. both actor and node started to act as before, camera turns 180 and nodes 90......uuuh. i am so f.... please can u help me with some sourcecode? or you still dont have pc to try some? i wish u could use my pc :cry: . i will try to attach another node to the character->mNode() and retrieve its orientation, im sure this wont work..... :evil: ......

i will post my 3d camera code later, i dont have internet connection home. i have to bring it from there. thanks for ur quick replys. but im still stuck

betajaen

30-04-2006 17:44:58

Don't apply any rotation to the NxActor or Controller directly, use the turn methods.

As for my idea just try this. (Excuse the bad ASCII drawing)

Create a SceneNode called MouseNode. Set the position to 0,0,0, don't attach it to anything except the root scene node.

In your frameListener do this:-



mRotX = Degree(-mInputDevice->getMouseRelativeX() * 0.13);
mRotY = Degree(-mInputDevice->getMouseRelativeY() * 0.13);

MouseNode->yaw(mRotX);



Then do this:


mPlayer->turn(MouseNode->getOrientation());


Then attach your Camera to mNode of mPlayer, then set the position as so:-



O
-+-
| >=OO= Camera: Position (-10,1,0), lookAt(Character Pos)
/ \...........................|



Then every frame you need to lookAt(mPlayer's position).

The mouseNode then should turn when you move the mouse, the orientation is carried over to mPlayer which rotates the character, and the camera. :D

dupleg

30-05-2006 14:48:50

oh thanks, now it works :lol: ..... i had to edit the core file so the character body rotations should not be set to the mesh node automatically. thanx man :wink:

wilson

30-11-2006 16:29:41

I kind of have the same problem.

When I followed betajaen's suggestions I experienced something I can't really explain.

As soon as I attach the camera to the mNode of the character, so it is positioned accordingly things start to behave strange, in the way, that the characters rotates different from the camera (the same way dupleg described).

The following code is executed for every frame.

1st person mode (camera's position is set manually, it is not attached to the character):


mRotX = Degree(-camRotX * 0.13);
mRotY = Degree(-camRotY * 0.13);
camera->yaw(mRotX);
camera->pitch(mRotY);

mouseNode->yaw(mRotX);
activePlayer->getNxCharacter()->turn(mouseNode->getOrientation());

playerPos = NxTools::convert(activePlayer->getNxCharacter()->mController->getActor()->getGlobalPosition());
camera->setPosition(Vector3(playerPos.x,playerPos.y+2,playerPos.z));


3rd person mode (camera is attached to character mNode):


mRotX = Degree(-camRotX * 0.13);
mRotY = Degree(-camRotY * 0.13);
camera->yaw(mRotX);
camera->pitch(mRotY);

mouseNode->yaw(mRotX);
activePlayer->getNxCharacter()->turn(mouseNode->getOrientation());

playerPos = NxTools::convert(activePlayer->getNxCharacter()->mController->getActor()->getGlobalPosition());
camera->lookAt(playerPos);


The thing is I like to attach the camera in both modes (1st,3rd person) to the character.
Using the lookAt for 1st person makes the character stare on the ground obviously (camera and character share the same position). Not using lookAt and turning the camera via yaw and the character indirectly via the mouseNode with yaw produces different results in the rotation.
On the other hand getting the orientation from the character and applying it to the camera produces very funky results.

I would be happy if I could apply all input to the character and then control the camera with the current status of the character (position, orientation).

I hope I made myself or my problem understandable.

wilson

04-12-2006 13:23:53

OK, solved it myelf. Problem was when the camera is attached to the character mNode, then the rotation was applied two times (once to the camera and the other time to the character itself).

betajaen

04-12-2006 14:34:30

There you go ;)

On another note with the character, I've re-implemented jumping and falling states, and it goes up and down stairs a lot better.