SA-MP Forums Angle Issues: Setting a attached object on a vehicle to face a vehicle
 New Account Members List Search Today's Posts Mark Forums Read

 10/07/2012, 05:50 AM #1 Kar High-roller     Join Date: May 2010 Location: Black Asylum Posts: 3,211 Reputation: 497 Angle Issues: Setting a attached object on a vehicle to face a vehicle Ok, for awhile now I've been trying to set a minigun machine to face another vehicle's position. But it's not working correctly, I tried all kinds of different methods.. with some methods it works when both vehicles are at certain angles to each other but otherwise it won't work. This video will explain everything. [ame]http://www.youtube.com/watch?v=LqsTQy03fXs[/ame] Here's the code(s) I've used. Code: new Float:x, Float:y, Float:z, Float:x2, Float:y2, Float:Angle, Float:damage, closestvehicle = GetClosestVehicle(playerid, 25.0); GetVehiclePos(vehicleid, x, y, z); GetVehiclePos(closestvehicle, x2, y2, z); if(closestvehicle == INVALID_VEHICLE_ID || !(1 <= closestvehicle <= 2000)) { Angle = 95.0; // this is the angle whereas the minigun faces to the front point of the vehicle. } else { //Angle = (95.0 + 360.0) - atan2( x - x2, y - y2 ); //Angle = 95.0 - atan2(x - x2, y - y2); //Angle = atan2(y - y2, x - x2) - 90.0 + 95.0; //Angle = atan2(y - y2, x - x2) - 90.0; //Angle = atan2(DestY - y, DestX - x) + 270.0; Angle = PointAngle(vehicleid, x, y, DestX, DestY) - 180.0; MPClamp360(Angle); } //SendClientMessageFormatted(playerid, -1, "[System] - playerid: %d - closestvehicleid: %d - Angle: %f - Angle2D - 95.0: %f", playerid, closestvehicle, Angle, (Angle - 95.0)); AttachObjectToVehicle(PlayerInfo[playerid][pSpecial_Missile_Object], vehicleid, 0.1, -0.5, 1.5, 0.0, 30.0, Angle); EDIT: PointAngle seems to do the trick.. wondering if there is any other way Code: stock Float:PointAngle(vehicleid, Float:xa, Float:ya, Float:xb, Float:yb) { new Float:carangle, Float:xc, Float:yc, Float:angle; xc = floatabs(floatsub(xa, xb)); yc = floatabs(floatsub(ya, yb)); if (yc == 0.0 || xc == 0.0) { if(yc == 0 && xc > 0) angle = 0.0; else if(yc == 0 && xc < 0) angle = 180.0; else if(yc > 0 && xc == 0) angle = 90.0; else if(yc < 0 && xc == 0) angle = 270.0; else if(yc == 0 && xc == 0) angle = 0.0; } else { angle = atan(xc / yc); if(xb > xa && yb <= ya) angle += 90.0; else if(xb <= xa && yb < ya) angle = floatsub(90.0, angle); else if(xb < xa && yb >= ya) angle -= 90.0; else if(xb >= xa && yb > ya) angle = floatsub(270.0, angle); } GetVehicleZAngle(vehicleid, carangle); return floatadd(angle, -carangle); } __________________ Last edited by Kar; 10/07/2012 at 01:40 PM.
 10/07/2012, 08:39 PM #2 RyDeR` High-roller     Join Date: Feb 2009 Location: Belgium Posts: 3,063 Reputation: 694 Re: Angle Issues: Setting a attached object on a vehicle to face a vehicle Sure, try this: Code: new Float: fAZ ; GetVehicleZAngle(vehicleid, fAZ); atan2(y - DestY, x - DestX) - fAZ - 180.0; __________________ Sup?
 11/07/2012, 12:37 AM #3 Kar High-roller     Join Date: May 2010 Location: Black Asylum Posts: 3,211 Reputation: 497 Re: Angle Issues: Setting a attached object on a vehicle to face a vehicle Ah the logic makes sense now, it works. Thanks! __________________

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post DJGama101 Scripting Help 1 05/04/2012 08:22 PM Kasis Scripting Help 3 06/11/2011 02:02 PM Pooh7 Help Archive 10 20/07/2011 07:46 PM LegendNissanGTR Help Archive 0 11/12/2010 02:36 PM corne Help Archive 18 29/11/2010 11:09 AM

All times are GMT. The time now is 02:36 PM.

 -- (EN) English -- (RU) Русски Contact Us - SA-MP - Archive - Top