What are you talking about? I've had this working on my own for a long time. The only problem was that for my pitch code, you don't set the x component to zero.
Here's some code of a bad guy that fires bullets ever x number of seconds in the direction of the player. It decomposes the vector connecting their positions into euler angles, rotates it out, and its direction is the same as the direction vector PlayerPos - EnemyPos
Code:
void Physics_Bert::Update()
{
// Vector3D to = Export.mpPlayer->mPosition - mPosition;
// to.Normalize();
// if(DotProduct(&to,&mLinearVelocity)<0 && mLinearVelocity.BasicLength() > 50)
// {
mLinearVelocity *= 1-(2*gpPhysics->mFrameTime);
// }
// else
// mLinearVelocity += to *METER(5)*gpPhysics->mFrameTime;
// gpPhysics->UpdateNormalizedLinearVel(this);
// Vector3D toplayer(Export.mpPlayer->mPosition.x-mPosition.x,Export.mpPlayer->mPosition.y,Export.mpPlayer->mPosition.z-mPosition.z);
// toplayer.y = 0;
Vector3D toplayer = Export.mpPlayer->mPosition - mPosition;
Vector3D Pitch;
Vector3D Yaw;
Pitch = toplayer;
Yaw = toplayer;
Yaw.y = 0;
Yaw.Normalize();
mYaw = RAD2DEG(acosf(-Yaw.z));
Pitch.Normalize();
mPitch = RAD2DEG(asinf(Pitch.y));
if(Export.mpPlayer->mPosition.x > mPosition.x)
mYaw = -mYaw;
static int curmis = 0; //current missile
FireTimer.Update();
Vector3 FireVector(0,0,-1);
Matrix3x3 RotationVector;
RotationVector.InitFromAngles(mPitch,mYaw,0);
RotationVector.TransformDir(&FireVector);
toplayer.Normalize();
char message[1024];
char message1[1024];
memset(message,0,sizeof(char)*1024);
memset(message1,0,sizeof(char)*1024);
sprintf(message,"ToPlayerVector: %f, %f, %f",toplayer.x,toplayer.y,toplayer.z);
sprintf(message1,"FireVector: %f, %f, %f", FireVector.x,FireVector.y,FireVector.z);
gpTextManager->ClearScreenText();
gpTextManager->PushLineOfText(message,-1024);
gpTextManager->PushLineOfText(message1,-1024);
if(FireTimer.mTimeBuffer > 60) //If x seconds has passed fire a bullet towards the player, this does not correct for the player's velocity (just fires towards player)
{
++curmis;
if(curmis > 10) //which missile we are firing
curmis = 0;
// Vector3D toplayer = Export.mvPhysicsObjects[0]->mPosition - mPosition;
double distance = toplayer.GetLength();
if(distance > mRadius + Export.mvPhysicsObjects[0]->mRadius + mMissile[curmis].mRadius + METER(1))
{
toplayer *= (1/distance); //normalize
mMissile[curmis].mPosition = mPosition + (toplayer * (mMissile[curmis].mRadius+mRadius));
mMissile[curmis].mLinearVelocity = Vector3ToVector3D(FireVector)*METER(50);//toplayer*METER(50);
gpPhysics->UpdateNormalizedLinearVel(&mMissile[curmis]);
}
FireTimer.ResetTimeBuffer();
}
return;
}