walking forward?
walking forward?
I've been trying for a week now. My character refuses to walk forward. It walks in some relation to the gaming world. How the heck do I get it to follow its nose??
I've tried to alter X, Y and Z on the position vector. I've tried to use a matrix. But it refuses to walk in any other direction.
If someone has solved this, would you like to post the code so I can see how you did??
I've tried to alter X, Y and Z on the position vector. I've tried to use a matrix. But it refuses to walk in any other direction.
If someone has solved this, would you like to post the code so I can see how you did??
reinvention
i thought my post from this thread (http://irrlicht.sourceforge.net/phpBB2/ ... .php?t=773) explained how to move a node in the direction that the camera is looking.. have you tried that?
if you want the character to always walk forward no matter how the camera is looking then you need to define a 'forward' vector and current rotation (although you could get these from ISceneNode)
now assuming that you start the model facing the positive X direction then try this code:
the tricky part is to update the vector when the user presses left or right which will rotate the 'forward' vector
i hope this helps
if you want the character to always walk forward no matter how the camera is looking then you need to define a 'forward' vector and current rotation (although you could get these from ISceneNode)
now assuming that you start the model facing the positive X direction then try this code:
Code: Select all
//global forward direction vector and rotation for node
float curr_rotation = 0.0f;
vector3df forward(1,0,0);
// when the user presses 'W' on keyboard move node 'forward'
node->setPosition( node->getPosition() + forward );
Code: Select all
//user has pressed left, update 'forward' vector
curr_rotation += 10;
if (curr_rotation >= 360.0f) curr_rotation -= 360.0f
forward.X = cos( curr_rotation*PI/180.0f );
forward.Z = sin( curr_rotation*PI/180.0f );
//user has pressed right, update 'forward' vector
curr_rotation -= 10;
if (curr_rotation <= 0.0f) curr_rotation += 360.0f
forward.X = cos( curr_rotation*PI/180.0f );
forward.Z = sin( curr_rotation*PI/180.0f );
-
- Posts: 386
- Joined: Thu Sep 25, 2003 12:43 pm
- Contact:
if you wanted to more tightly integrate your code with irrlicht then you could do something like this:
Code: Select all
// when the user presses 'W' on keyboard move node 'forward'
// first determin which way is 'forward'
vector3df forward( cos( node->getRotation().Y*PI/180.0f, 0, sin( node->getRotation().Y*PI/180.0f );
//now move 'forward' 10 units
node->setPosition( node->getPosition() + forward*10.0f );
//when the user presses 'A' turn the node to the left
node->setRotation( vector3df(0,node->getRotation().Y + 10.0f,0);
//when the user presses 'D' turn the node to the left
node->setRotation( vector3df(0,node->getRotation().Y - 10.0f,0);
-
- Posts: 386
- Joined: Thu Sep 25, 2003 12:43 pm
- Contact:
-
- Posts: 386
- Joined: Thu Sep 25, 2003 12:43 pm
- Contact:
I tried switching my code with what you have here, and it .. kinda works. But isn't accurate. It doesn't go by the players rotation or somethin. My model is facing the way the camera is facing.... I move it forward it decides to move left... I turn it around backwards, it moves right. It just keeps moving in random directions when it rotates.rt wrote:if you wanted to more tightly integrate your code with irrlicht then you could do something like this:
Code: Select all
// when the user presses 'W' on keyboard move node 'forward' // first determin which way is 'forward' vector3df forward( cos( node->getRotation().Y*PI/180.0f, 0, sin( node->getRotation().Y*PI/180.0f ); //now move 'forward' 10 units node->setPosition( node->getPosition() + forward*10.0f ); //when the user presses 'A' turn the node to the left node->setRotation( vector3df(0,node->getRotation().Y + 10.0f,0); //when the user presses 'D' turn the node to the left node->setRotation( vector3df(0,node->getRotation().Y - 10.0f,0);
i think irrlicht works in a different manner than i assumed.. try this code:HIM wrote:The rotation part seems to work. The walking part doesn't... the model seems to run off in another direction.
Is it the model that is contructet in a strange way perhaps?? I'm using the Sydney.md2 model..
Code: Select all
// when the user presses 'W' on keyboard move node 'forward'
// first determin which way is 'forward'
vector3df forward( sin( node->getRotation().Y*PI/180.0f ), 0, cos( node->getRotation().Y*PI/180.0f ) );
//now move 'forward' 10 units
node->setPosition( node->getPosition() + forward*10.0f );
//when the user presses 'A' turn the node to the left
node->setRotation( vector3df(0,node->getRotation().Y - 10.0f,0));
//when the user presses 'D' turn the node to the left
node->setRotation( vector3df(0,node->getRotation().Y + 10.0f,0));
-
- Posts: 386
- Joined: Thu Sep 25, 2003 12:43 pm
- Contact:
yes. basically it simplifies things by breaking your 3D forward vector into just its X-component and just the Z-component.
If you think about your rotation around the Y axis, this is the same as some angle around a point on the X-Z plane. Imagine a hypotenues sticking out from the origin based on this angle. Now, as you recall from basic Trigonometry, SOH CAH TOA: the 'opposite' side's length is equal to Sin(Hypoteneus) and the 'adjacent' size's length is equal to Cos(Hypotenenus). So, we can get Unit-Normalized Vector components in the X and Z axis by taking the Opposite and Adjacent sides from our angle.
Now, because we have a Unit-Normalized Vector, we can multiply it by a scalar value to get a vector in the right direction, with the scalar's length. (Its like multiplying 1*Scalar, where our '1' also signifies direction).
Adding this vector to our position puts us 'Scalar' number of units in the 'Forward' direction.
The end.
If you think about your rotation around the Y axis, this is the same as some angle around a point on the X-Z plane. Imagine a hypotenues sticking out from the origin based on this angle. Now, as you recall from basic Trigonometry, SOH CAH TOA: the 'opposite' side's length is equal to Sin(Hypoteneus) and the 'adjacent' size's length is equal to Cos(Hypotenenus). So, we can get Unit-Normalized Vector components in the X and Z axis by taking the Opposite and Adjacent sides from our angle.
Now, because we have a Unit-Normalized Vector, we can multiply it by a scalar value to get a vector in the right direction, with the scalar's length. (Its like multiplying 1*Scalar, where our '1' also signifies direction).
Adding this vector to our position puts us 'Scalar' number of units in the 'Forward' direction.
The end.
a screen cap is worth 0x100000 DWORDS
yah... what he saidkeless wrote:yes. basically it simplifies things by breaking your 3D forward vector into just its X-component and just the Z-component.
If you think about your rotation around the Y axis, this is the same as some angle around a point on the X-Z plane. Imagine a hypotenues sticking out from the origin based on this angle. Now, as you recall from basic Trigonometry, SOH CAH TOA: the 'opposite' side's length is equal to Sin(Hypoteneus) and the 'adjacent' size's length is equal to Cos(Hypotenenus). So, we can get Unit-Normalized Vector components in the X and Z axis by taking the Opposite and Adjacent sides from our angle.
Now, because we have a Unit-Normalized Vector, we can multiply it by a scalar value to get a vector in the right direction, with the scalar's length. (Its like multiplying 1*Scalar, where our '1' also signifies direction).
Adding this vector to our position puts us 'Scalar' number of units in the 'Forward' direction.
The end.