Rotate Player Problem
by Nathan Cox · in Torque Game Engine · 07/22/2010 (4:52 pm) · 7 replies
Ok, I'm currently using Eric Hartman's Hook Code (you can find it with a quick search for grapple hook) but instead of creating an animation for hooking, I want to rotate the player so that the player's head is pointing towards the hook position. How would I do this?
If it helps, here is the extract of code that applies the physics:
If it helps, here is the extract of code that applies the physics:
//EGH: grapling hook forces
VectorF t;
t = getPosition() - hookPos;
float dist;
if( hookLen != -1 )
{
//if beyond hook length, apply force proportional to distance
dist = ((t.x * t.x) + (t.y * t.y) + (t.z * t.z));
if(dist > (hookLen*hookLen) )
{
//Con::warnf("Beyond HookLen");
mVelocity += (1000 * moveVec/ mMass) * TickSec;
//do something!
t.normalize();
F32 vMag;
vMag = mSqrt((mVelocity.x * mVelocity.x) + (mVelocity.y * mVelocity.y) + (mVelocity.z * mVelocity.z));
if(vMag != 0)
{
if(mAcos(mDot(t, mVelocity)/vMag) < 1.57)
{
mVelocity -= (mDot(t, mVelocity)/mDot(t, t)) * t ;
mVelocity.normalize();
mVelocity *= vMag;
}
}
}
else
{
//Con::warnf("Inside HookLen");
}
}
//<-EGHAbout the author
#2
07/28/2010 (8:51 pm)
On any normal object you could use setTransform after creating a matrix that is aligned with your velocity vector. The problem with the player though is that it overrides setTransform and removes all rotation along the x axis and y axis. That is in there to always keep the player aligned with the z axis.
#3
That way if you hook something you still are standing, but if you swing off a building, it looks like you are actually swinging.
07/29/2010 (4:46 pm)
Is there a way to, perhaps, make it so it doesn't remove x and y rotation when in the air.That way if you hook something you still are standing, but if you swing off a building, it looks like you are actually swinging.
#4
Really the easiest way to handle what you're trying to do is use an animation.
07/29/2010 (5:52 pm)
You could edit Player::setTransform in Player.cc, comment out the code there and call Parent::setTransform instead. Doing that though may cause some serious issues with your player objects. I have a feeling it will not be what you want in the end.Really the easiest way to handle what you're trying to do is use an animation.
#5
07/29/2010 (8:54 pm)
The Player class makes a lot of assumptions throughout its inner workings that it will be oriented with the world z axis. I've written a resource to remove these assumptions and use a quaternion to store the player's rotation, but it's a very extensive modification and probably overkill for your needs. An animation sounds like a good way to go.
#6
07/31/2010 (7:57 pm)
Dude you should post a link to the resource you are referring to. You are already asking people to help (which is fine) but now you want them to search through the threads to find the resource of which you are referring to.
#7
http://www.torquepowered.com/community/forums/viewthread/19947
Also, if you want to understand what i mean, check out Eric's game Age of Time to see the player rotate when the hook is used.
08/07/2010 (2:51 pm)
It isn't strictly a recourse. It was posted in this thread:http://www.torquepowered.com/community/forums/viewthread/19947
Also, if you want to understand what i mean, check out Eric's game Age of Time to see the player rotate when the hook is used.
Torque Owner Nathan Cox
So no one has any clue how to change the x and y rotation of the character so that at any z rotation the player will be tilted towards the hookpos? (like being dragged)