SA-MP Forums Archive
Rotating a vehicle - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Rotating a vehicle (/showthread.php?tid=493030)



Rotating a vehicle - Wizzy951 - 06.02.2014

Guys, I am working on a project for my server and I was wondering if there is a way to rotate non-occupied vehicles in 360 degrees ? Even thought I am going to use an object to rotate the vehicles.


Re: Rotating a vehicle - Wizzy951 - 07.02.2014

Bump after more than 24 hours.


Re: Rotating a vehicle - Ari - 07.02.2014

pawn Код:
GetVehicleZAngle(currentveh, angle);
SetVehicleZAngle(currentveh, angle);



Re: Rotating a vehicle - Wizzy951 - 07.02.2014

Should I make it 360 times to rotate it fully or somehow through a loop ?
P.S: it's a joke about 360 times.


Re: Rotating a vehicle - Wizzy951 - 09.02.2014

Bump still need help with it. I tried something and it doesn't work.


AW: Rotating a vehicle - NaS - 09.02.2014

Use a Timer..

Код:
//OnGameModeInit:

SetTimer("RotateVehicle", 1000, 1);

// e.g. bottom of your script:

forward RotateVehicle();
public RotateVehicle()
{
new Float:angle;
GetVehicleZAngle(vehicleid, angle);
SetVehicleZAngle(vehicleid, angle + 5.0); // Turn vehicleid by 5 degrees
}
The vehicle ("vehicleid" has to be replaced by your ID) will now turn by 5 degrees every second.


Re: AW: Rotating a vehicle - LiamM - 09.02.2014

Quote:
Originally Posted by Ari
Посмотреть сообщение
pawn Код:
GetVehicleZAngle(currentveh, angle);
SetVehicleZAngle(currentveh, angle);
Quote:
Originally Posted by NaS
Посмотреть сообщение
Use a Timer..

Код:
//OnGameModeInit:

SetTimer("RotateVehicle", 1000, 1);

// e.g. bottom of your script:

forward RotateVehicle();
public RotateVehicle()
{
new Float:angle;
GetVehicleZAngle(vehicleid, angle);
SetVehicleZAngle(vehicleid, angle + 5.0); // Turn vehicleid by 5 degrees
}
The vehicle ("vehicleid" has to be replaced by your ID) will now turn by 5 degrees every second.
Just to clarify guys... Wizzy asked us "is there is a way to rotate non-occupied vehicles in 360 degrees"

Both solutions you have supplied will not work... The SetVehicleZAngle only works when the vehicle is occupied. Making it completely useless in the situation that it's required for. I found this out through extensive bug testing with a vehicle respawn system I scripted. I ended up searching half the world looking for a solution on why the cars weren't rotating the way I'd scripted them too, until I stumbled across a post which actually stated that the "SetVehicleZAngle" function only works when the vehicle is occupied. If it's un-occupied you could pretty much say the script "looks over" it.

However.. I'm not going to leave without providing some kind of solution to you as I did in fact get my system to work. The way I got my system to work was actually by deleting the vehicle, and re-creating it with the same position as before but changing the Z / A (rotational) angle. So something along the lines of:

pawn Код:
//GetVehiclePos(vehicleid, &Float:X, &Float:Y, &Float:Z);

GetVehiclePos(VehID, X, Y, Z);

//GetVehicleZAngle(vehicleid, &Float:Z); -- May I also note that this function works even with un-occupied vehicles. It's only the "SetVehicleZAngle" that doesn't.

GetVehicleZAngle(VehID, A);

//DestroyVehicle(vehicleid);

DestroyVehicle(VehID);

//CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);

CreateVehicle(model, X, Y, Z, A + 360, 0, 0, 5000);
Obviously you'd want to change the colours and what not if this was the steps you were willing to take. I'm unsure if "A + 360" would actually rotate it 360 degrees but it's worth a try. Hope this helped! Good luck with your vehicle rotating!


Re: Rotating a vehicle - Wizzy951 - 09.02.2014

Okay guys, thank you for the responses. I will try them now.


Re: Rotating a vehicle - LiamM - 09.02.2014

Quote:
Originally Posted by Wizzy951
Посмотреть сообщение
Okay guys, thank you for the responses. I will try them now.
Let us know if you get it working, one thing I don't like is when people fix something and they just say "Fixed it!". There is ALWAYS someone else out there to educate. Good Luck, Wizzy!


Re: Rotating a vehicle - cessil - 09.02.2014

you don't need to destroy the vehicle, using SetVehiclePos will also update the angle for the clients, so set the angle and then set the vehicle position