AttachObjectToVehicle rz angle problem with Angle2D? maybe
#1

ok so here is the , attachobject, note rz is at 95.0

pawn Код:
AttachObjectToVehicle(Vehicle_Machine_Special_Object[id], id, 0.1, -0.5, 1.5, 0.0, 30.0, 95.0);
so, i want this object to face a point. AKA - the point in this situation is another vehicle's pos.

so

pawn Код:
new Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:Angle, closestvehicle = GetClosestVehicle(playerid, 25.0);
            GetVehiclePos(vehicleid, x, y, z);
            GetVehiclePos(closestvehicle, x2, y2, z);
            Angle = Angle2D(x, y, x2, y2);
            SendClientMessageFormatted(playerid, -1, "[System] - playerid: %d - closestvehicleid: %d - Angle2D: %f - Angle2D + 95: %f", playerid, closestvehicle, Angle, 95.0 + Angle);
            AttachObjectToVehicle(Vehicle_Machine_Special_Object[vehicleid], vehicleid, 0.1, -0.5, 1.5, 0.0, 30.0, 95.0 + Angle);

stock Float:Angle2D(Float:PointAx, Float:PointAy, Float:PointBx, Float:PointBy)
{
    new Float:Angle;
    Angle = atan2(PointAy < PointBy ? PointBy - PointAy : PointAy - PointBy, PointAx < PointBx ? PointBx - PointAx : PointAx - PointBx);
    Angle = PointAx < PointBx ? 270.0 + Angle : 90.0 - Angle;
    Angle = PointAy < PointBy ? Angle : 180.0 - Angle;
    return Angle < 0.0 ? Angle + 360.0 : Angle;
}
everything works fine, but , sometimes, the angle is just pure wrong, for about 0 - 150 it kinda works nice. but otherwise, its just plain wrong or goes weird.

ok well, Angle2D seems to always be returning the correct angle, but you know that for attachobjecttovehicle you need a small offsets, thats 95.0, if you dont put 95.0+angle it wont even work at all because at 95.0 its actually looks like its at 0.0
Reply
#2

Getting a 2D angle should be much simpler

pawn Код:
stock Float:Angle2D(Float:PointAx, Float:PointAy, Float:PointBx, Float:PointBy)
{
    new Float:Angle;
    Angle = -atan2(PointBx - PointAx, PointBy - PointAy);
    return Angle;
}
Reply
#3

thanks! it works fine now, but one problem i have! ok say i face 2 vehicles at 0.0 then i do what im doing, it works fine. but say i put 1 vehicle at 0.0 then i set my zangle to 180, it doesnt work correctly! 180 needs to be added to it, but im wondering... when should i add 180?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)