Game Development Community

Some kind of SetForwardVector

by Andrei O. Victor · in Technical Issues · 07/11/2007 (6:30 pm) · 2 replies

Hello everyone.

I wish you could help me in figuring the right math for this (or perhaps another thing besides math).
I have a vector that i desire where my player will face forward. Now, I'm having trouble making my player to actually face that direction.

Here's my take so far:

function TargetObjects::FaceTarget( %this, %obj )
{
    %angle = mAcos( VectorDot(
        VectorNormalize( VectorSub( nameToID( "cam_PlayerView" ).getPosition(),
        %obj.getPosition() ) ),
        VectorNormalize( %obj.getForwardVector() ) ) );
    error("Obj(" @ %obj.getId() @ "):" SPC mDegToRad( %angle) );
    %pos = %obj.getPosition();
    //%rot = getWords( %obj.getTransform(), 3 );
    %rot = "0 0 1" SPC mDegToRad( %angle );
    %obj.setTransform( %pos SPC %rot );
}

It simply doesn't do the job? What's wrong?

#1
07/11/2007 (7:29 pm)
This comes up often in the forums; one thread is here.
#2
07/11/2007 (7:32 pm)
Oh but one thing that stands out is that i'm pretty sure mAcos returns radians, not degrees,
so your call to mDegToRad() ain't needed.

a good general approach to debugging things like this is to bust it up into component steps who's correctness you can verify.

ie, your huge mAcos line could be busted up into a bunch of sub operations, the results of each of which you could echo to the console.