[SOLVED] A little help using the character controller

Ridhan

23-03-2007 17:14:04

Hi, currently I'm making an attempt of a game, and I was using character controllers for players and enemies.
At the moment, my objective is make my enemies to face in the direction my character stands. For that, I simply used the example in the intermiediate tutorial, and used the turn method instead of the rotate.
The problem is that the enemy character start to spin very fast. The code I use is the folowing:

void GameMonster::turnToPlayer(GamePlayer *gp){

Vector3 posPlayer, posMonster, mDir, currentDir;
Quaternion q;

posPlayer = gp->gcCharacter->mNode->getPosition();

posMonster = gcCharacter->mNode->getPosition();

mDir = posPlayer - posMonster;
mDir.normalise();

currentDir = gcCharacter->mNode->getOrientation() * Vector3::NEGATIVE_UNIT_Z;
q = currentDir.getRotationTo(mDir);
gcCharacter->turn(q);
}


Thanks for the help.

Besides that, I want to know if there's any improvement in 0.6 for the character controller that is worth upgrading to this version.

jchmack

23-03-2007 20:59:56

i think you are trying this:


Vector3 target = LOOKATME->_getDerivedPosition();
Vector3 targetdirection = target - character1->mNode->_getDerivedPosition();
Vector3 currentdirection = character1->mNode->_getDerivedOrientation() * Vector3::NEGATIVE_UNIT_Z;

targetdirection.y=0;
currentdirection.y=0;
targetdirection.normalise();
currentdirection.normalise();

Quaternion quat = currentdirection.getRotationTo(targetdirection);
character1->turn(q);


just replace LOOKATME with a node you are trying to face or the Vector3 representation. And character1 with your character.

I had the same spinning thing until i removed the y component then it worked fine. But i guess this is only if you want to remove the y component. But then again i dont see a need to have a character turn upward.

as for the character improvements... i just upgraded from 0.4 to 0.6 and i beleive betajaen Has been working on the character movements because some of the things like going up stairs has improved. At first my characters were falling through the floor but you just had to change the skin width. The problem now is that the characters seem to move faster when i have lower frame rates. Anyone else having these problems with 0.6?

Ridhan

24-03-2007 02:47:16

Thank you for your answer.
I tried your solution but my monster character keep spining no matter what. Spend the rest of the day figuring out what's wrong but I couldn't guess...

jchmack

24-03-2007 11:50:43

Thank you for your answer.
I tried your solution but my monster character keep spining no matter what. Spend the rest of the day figuring out what's wrong but I couldn't guess...


try replacing all of that with just a lookat() function to see if your character still spins. This way you can at least tell if it something in there or some other factor.

Ridhan

24-03-2007 16:42:30

Well, I used the lookAt function. First I used it like this:

Node->lookAt(gp->gcNode->_getDerivedPosition(), Ogre::Node::TS_LOCAL);

And the spinning continued. Then I changed it to:

Node->lookAt(gp->gcNode->_getDerivedPosition(), Ogre::Node::TS_WORLD);

and it worked perfectly. Now, I don't how to reflect this in the other code...

jchmack

25-03-2007 13:51:31

Ok a few questions:

1) What are you trying to turn to look at something

Node->lookAt(..
^
what is this node.

you should be turning the character not the node. Because it would just spin the mesh attached to it.
mPlayer->turn(q);

2) What are you looking at?

if your target node is a child node of your character then when you turn the character the target will move with it causing a spin.

3) Does the speed of the spin vary?
Does it start off spinning? Does it spin faster when you do something?

If the speed is constant i would say that your target is a child of your character. If it gets faster/slower i would say you are using the wrong scope TS_LOCAL vs TS_WORLD gcNode->_getDerivedPosition() vs gcNode->getWorldPosition().

hope this helps =)

Ridhan

25-03-2007 18:51:42

Yes!

Finally i made it!

I'll try to explain it the best i can...

turn() does not turn the capsule based on the current orientation, like rotate(). Instead, turn() only does a setOrientation(), overriding the last orientation. So, doing a getRotationTo() just gives me an offset value based on my current orientation, and what I really needed is a absolute orientation.

Resuming, because I have to go to lunch xD, I've changed this line



mCharacter->turn(q)

for this

mCharacter->turn(q * mCharacter->mNode->getOrientation())

Thanks jchmack for all the help :D !

odyeiop

25-03-2007 20:27:21

Oh sweet zombie jesus. This is EXACTLY what I have been looking for for the past couple of hours. Thank you sooooo much both of you =)

If you're ever in Ontario I'll buy you a cookie.