Fail didn't get it properly output it to LUA either. Its working now. ! more question good sir.Rotation is that the actual Yaw pitch roll of the unit or the facing angle in radians? Everywhere i look for getRotation on this site its people referring to the Facing angle or the Float that is in the movement struct right after the Z value. Not that actual Yaw/Pitch/Roll values.
Also IDA defines it like this
int __userpurge CGObject_C::GetRotation@<eax>(int a1@<ecx>, double a2@<st0>, int a3)
Do you know what the last 2 args are?
Thanks for all your help, I really appreciate your patience.
Edit:
OK making a little progress. I switched from doing to computation on the LUA side to the C++ side. Seems to be working but hitting traps at the wrong side running forward it shots a bit left. I think my velocityVector is incorrect.
Code:
int32 direction = (WoWMovementFlag)(unit->GetMovementFlags() & 0xFF);
C3Vector velVec;
if (direction == 1) // Running forward6
{
velVec = C3Vector(0, 7, 0);
}
else if (direction == 2) // Running backward
{
velVec = C3Vector(0, -7, 0);
}
else if (direction == 4) // Strafing right
{
velVec = C3Vector(7, 0, 0);
}
else if (direction == 8) // Strafing left
{
velVec = C3Vector(-7, 0, 0);
}
C3Vector me;
ObjectMgr::getlocalPlayer()->GetPosition(me);
aimPos = FindInterceptVector(me, 25, pos, velVec);
Code:
C3Vector FindInterceptVector(C3Vector shotOrigin, float shotSpeed,
C3Vector targetOrigin, C3Vector targetVel) {
C3Vector dirToTarget = targetOrigin - shotOrigin;
dirToTarget.normaliZeVector3D();
// Decompose the target's velocity into the part parallel to the
// direction to the cannon and the part tangential to it.
// The part towards the cannon is found by projecting the target's
// velocity on dirToTarget using a dot product.
C3Vector targetVelOrth = targetVel.dotVector3D(dirToTarget) * dirToTarget;
// The tangential part is then found by subtracting the
// result from the target velocity.
C3Vector targetVelTang = targetVel - targetVelOrth;
/*
* targetVelOrth
* |
* |
*
* ^...7 <-targetVel
* | /.
* | / .
* |/ .
* t---> <-targetVelTang
*
*
* s---> <-shotVelTang
*
*/
// The tangential component of the velocities should be the same
// (or there is no chance to hit)
// THIS IS THE MAIN INSIGHT!
C3Vector shotVelTang = targetVelTang;
// Now all we have to find is the orthogonal velocity of the shot
float shotVelSpeed = shotVelTang.GetMagnitude();
if (shotVelSpeed > shotSpeed) {
// Shot is too slow to intercept target, it will never catch up.
// Do our best by aiming in the direction of the targets velocity.
targetVel.normaliZeVector3D();
return targetVel * shotSpeed;
}
else {
// We know the shot speed, and the tangential velocity.
// Using pythagoras we can find the orthogonal velocity.
float shotSpeedOrth =
sqrt(shotSpeed * shotSpeed - shotVelSpeed * shotVelSpeed);
C3Vector shotVelOrth = dirToTarget * shotSpeedOrth;
// Finally, add the tangential and orthogonal velocities.
// Find the time of collision (distance / relative velocity)
float timeToCollision = ((shotOrigin - targetOrigin).GetMagnitude())
/ (shotVelOrth.GetMagnitude() - targetVelOrth.GetMagnitude());
// Calculate where the shot will be at the time of collision
C3Vector shotVel = shotVelOrth + shotVelTang;
C3Vector shotCollisionPoint = shotOrigin + shotVel * timeToCollision;
return shotCollisionPoint;
}
}