Game Development Community

Rotate player's head to face a point

by Nathan Cox · in General Discussion · 07/19/2010 (5:55 pm) · 1 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:

//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");
		}
	}
	//<-EGH