Rotate player around X or Y axis
by Eric den Boer · in Torque 3D Professional · 07/28/2009 (1:52 pm) · 23 replies
Hi all,
What I want to create is the following: have a player collide with a TSStatic, and when a certain flag on that static is set to true, have it scale the object, or walk on the wall of the object. Now, I've got the flags going and all that but now I'm running into the problem that I cannot rotate the player around its X or Y axis. Only around the Z-axis, using the mRot member.
Now, naturally I went looking for what caused this and I found out that the X and Y of mRot is never taken into account. Okay, good... so I changed things in setPosition and setRenderPosition etc. to have it take the X and Y of mRot into account.
However, when I set the rotation around the X axis to say 0.5, it won't work. How do I get the player objec to rotate around the X-axis, so I can then start working on having it run over the verticle surface of the object.
Thanks!
What I want to create is the following: have a player collide with a TSStatic, and when a certain flag on that static is set to true, have it scale the object, or walk on the wall of the object. Now, I've got the flags going and all that but now I'm running into the problem that I cannot rotate the player around its X or Y axis. Only around the Z-axis, using the mRot member.
Now, naturally I went looking for what caused this and I found out that the X and Y of mRot is never taken into account. Okay, good... so I changed things in setPosition and setRenderPosition etc. to have it take the X and Y of mRot into account.
void Player::setPosition(const Point3F& pos,const Point3F& rot)
{
MatrixF mat;
if (isMounted()) {
// Use transform from mounted object
MatrixF nmat,zrot;
mMount.object->getMountTransform(mMount.node,&nmat);
zrot.set(EulerF(rot.x, rot.y, rot.z)); // CHANGED THIS
mat.mul(nmat,zrot);
}
else {
mat.set(EulerF(rot.x, rot.y, rot.z)); // CHANGED THIS
mat.setColumn(3,pos);
}
Parent::setTransform(mat);
mRot = rot;
if ( mPhysicsPlayer )
mPhysicsPlayer->setPosition( mat );
}
void Player::setRenderPosition(const Point3F& pos, const Point3F& rot, F32 dt)
{
MatrixF mat;
if (isMounted()) {
// Use transform from mounted object
MatrixF nmat,zrot;
mMount.object->getRenderMountTransform(mMount.node,&nmat);
zrot.set(EulerF(rot.x, rot.y, rot.z)); // CHANGED THIS
mat.mul(nmat,zrot);
}
else {
EulerF orient(rot.x, rot.y, rot.z); // CHANGED THIS
mat.set(orient);
mat.setColumn(3, pos);
if (inDeathAnim()) {
F32 boxRad = (mDataBlock->boxSize.x * 0.5f);
if (MatrixF * fallMat = mDeath.fallToGround(dt, pos, rot.z, boxRad))
mat = * fallMat;
}
else
mDeath.initFall();
}
Parent::setRenderTransform(mat);
}However, when I set the rotation around the X axis to say 0.5, it won't work. How do I get the player objec to rotate around the X-axis, so I can then start working on having it run over the verticle surface of the object.
Thanks!
#22

This is what's happening btw.
edit: I'll check it out. Will this enable me to apply the rotation to the player's movement?
09/11/2009 (4:34 pm)

This is what's happening btw.
edit: I'll check it out. Will this enable me to apply the rotation to the player's movement?
#23
Acceleration should be calculated using the contactNormal.
In updateMove() go to the fragment of triggering jump.
replace:
with this:
Also your gravity should be recalculated:
will become:
09/12/2009 (6:48 am)
Now i understand why when jumping you flip.Acceleration should be calculated using the contactNormal.
In updateMove() go to the fragment of triggering jump.
replace:
acc.z += scaleZ * impulse * zSpeedScale;
with this:
acc += contactNormal * scaleZ * impulse * zSpeedScale;
Also your gravity should be recalculated:
VectorF acc(0.0f, 0.0f, mGravity * mGravityMod * TickSec);
will become:
VectorF acc; acc.zero(); acc = contactNormal;//a possible findcontact() call here acc.neg(); acc *= mGravityMod * TickSec;
Torque Owner Ivan Mandzhukov
Liman3D
You should check very well what happens when jumping(in updatemove())
Input can be corrected in moveList or at the begining of updateMove().