A missile update function would look similar to this:
pawn Код:
//make sure this is defined before it is used, or get a reparse error
stock Float:GetAngleFromPosToPos(Float:X, Float:Y, Float:PointX, Float:PointY)
{
new Float:Angle;
if(X > PointX && Y > PointY)
Angle = floatabs(atan2(floatsub(PointX, X), floatsub(PointY, Y)));
if(X > PointX && Y <= PointY)
Angle = floatadd(floatabs(atan2(floatsub(Y, PointY), floatsub(PointX, X))), 270.0);
if(X <= PointX && Y > PointY)
Angle = floatadd(floatabs(atan2(floatsub(PointY, Y), floatsub(X, PointX))), 90.0);
if(X <= PointX && Y <= PointY)
Angle = floatadd(floatabs(atan2(floatsub(X, PointX), floatsub(Y, PointY))), 180.0);
return Angle >= 360.0 ? floatsub(Angle, 360.0) : Angle;
}
//This function makes objectid point to vehicle and move towards it
stock UpdateMissile(objectid, targetvehicle)
{
new
Float: fFromX,
Float: fFromY,
Float: fFromZ,
Float: fToX,
Float: fToY,
Float: fToZ
;
//save pos of missile and target so we can do angle calculations
GetObjectPos(objectid, fFromX, fFromY, fFromZ);
GetVehiclePos(targetvehicle, fToX, fToY, fToZ);
//get angle to target
new Float: fTargetAngle = GetAngleFromPosToPos(fFromX, fFromY, fToX, fToY);
//This is where you need to get offsets
//these are offsets i made for the arrow object (works perfect with the white arrow object)
SetObjectRot(objectid, 0.0, -90.00000, 90.0+fTargetAngle);
//use your own speeds for the missile
MoveObject(objectid, fToX, fToY, fToZ, 1.0);
}
Keep in mind the offsets used here are just for the white arrow, wont necessarily work for the missile.
Just wrote that quickly and not tested it, it's more so you can see the logic.
EDIT: Fixed some code