SA-MP Forums Archive
SetVehicleVelocity using Trig help - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: SetVehicleVelocity using Trig help (/showthread.php?tid=196356)



SetVehicleVelocity using Trig help - MW2_OWN3D - 05.12.2010

This is the code I use, but it doesn't work. "50" should be the player speed in the direction directly in front of the player's vehicle.
Код:
	if(!strcmp("/boost", cmdtext, true)) {
		new Float:x, Float:y, Float:z, Float:angle;
		GetVehicleZAngle(GetPlayerVehicleID(playerid),angle);
		x = floatcos(angle/4)*50;
		y = floatsin(90-(angle/4))*50;
		z = 0;
		SetVehicleVelocity(GetPlayerVehicleID(playerid),x,y,z);
		return 1;
	}
Can someone please help me to make this work.


Re: SetVehicleVelocity using Trig help - fangoth1 - 05.12.2010

ill try but this may not work
pawn Код:
if(!strcmp("/boost", cmdtext, true)) {
        new Float:x, Float:y, Float:z, Float:angle;
        new vehid = GetPlayerVehicleID(playerid);
        GetVehicleZAngle(vehid(playerid),angle);
        x = floatcos(angle/4)+50;
        y = floatsin(90-(angle/4))+50;
        z = 0;
        SetVehicleVelocity(vehid(playerid),x,y,z);
        return 1;
    }



Re: SetVehicleVelocity using Trig help - MW2_OWN3D - 05.12.2010

Thanks for the response. But changing the * to a + won't work as it would remove approx 80% of the difference of speed between the X and Y axis, making the car go at approx 45 degrees.


Re: SetVehicleVelocity using Trig help - MW2_OWN3D - 05.12.2010

nevermind, I worked it out but it turned out to be much, MUCH more complex.


Re: SetVehicleVelocity using Trig help - RSX - 05.12.2010

Quote:
Originally Posted by MW2_OWN3D
Посмотреть сообщение
nevermind, I worked it out but it turned out to be much, MUCH more complex.
He-he... if i could find my turbo code (It was on timer)... it was a day figuring out how to get the one line to work properly. But i managed to do it somewhat, maybe I can compare your/mine code?


Re: SetVehicleVelocity using Trig help - MW2_OWN3D - 06.12.2010

You'd look at the code of 1 second and then your head would explode... by the way, it doesn't use trig anymore.

i smell leechers

Код:
dcmd_setcarspeed(playerid,params[])
{
	new idx, tmp[256], tmp2[256], string[128], pid, Float:speed, Float:x, Float:y, Float:z, Float:xc, Float:yc, Float:zc, new Float:quat[4], Float:vectors[3] = {0.0,-1.0,0.0};
	if(hAdmin[playerid] || IsPlayerAdmin(playerid)) {
		tmp = strtok(params,idx);
		tmp2 = strtok(params,idx);
		pid = strval(tmp);
		speed = strval(tmp2);
	    if(!strlen(tmp)) return SendClientMessage(playerid, 0xFFFFFFFF, "Usage: /setcarspeed [playerid] [speed]");
		if(!IsPlayerConnected(pid)) return SendClientMessage(playerid,0xFFFFFFFF,"*** UFR Admin: Player not connected!");
		if(GetPlayerState(pid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid,COLOR_YELLOW,"ERROR: Not driving a vehicle.");
		GetVehicleVelocity(GetPlayerVehicleID(pid), xc, yc, zc);
		speed = floatsqroot((xc * xc) + (yc * yc) + (zc * zc)) + speed;
		GetVehicleRotationQuat(GetPlayerVehicleID(pid), quat[0], quat[1], quat[2], quat[3]);
		new Float:mainindex[4][4], Float:X_X = quat[0] * quat[0], Float:X_Y = quat[0] * quat[1], Float:X_Z = quat[0] * quat[2], Float:X_W = quat[0] * quat[3],
		Float:Y_Y = quat[1] * quat[1], Float:Y_Z = quat[1] * quat[2], Float:Y_W = quat[1] * quat[3], Float:Z_Z = quat[2] * quat[2], Float:Z_W = quat[2] * quat[3];
		mainindex[0][0] = 1-2*(Y_Y+Z_Z); mainindex[0][1]=2*(X_Y-Z_W); mainindex[0][2]=2*(X_Z+Y_W); mainindex[0][3]=0.0; mainindex[1][0]=2*(X_Y+Z_W); mainindex[1][1]=1-2*(X_X+Z_Z);
		mainindex[1][2] = 2*(Y_Z-X_W); mainindex[1][3]=0.0; mainindex[2][0]=2*(X_Z-Y_W); mainindex[2][1]=2*(Y_Z+X_W); mainindex[2][2]=1-2*(X_X+Y_Y);
		mainindex[2][3] = 0; mainindex[3][0]=0; mainindex[3][1]=0; mainindex[3][2]=0; mainindex[3][3]=1;
		z = vectors[2]*mainindex[0][0]+vectors[1]*mainindex[0][1]+vectors[0]*mainindex[0][2]+mainindex[0][3];
		y = vectors[2]*mainindex[1][0]+vectors[1]*mainindex[1][1]+vectors[0]*mainindex[1][2]+mainindex[1][3];
		x = -(vectors[2]*mainindex[2][0]+vectors[1]*mainindex[2][1]+vectors[0]*mainindex[2][2]+mainindex[2][3]);
		SetVehicleVelocity(GetPlayerVehicleID(pid), x * speed / 140, y * speed / 140, z * speed / 140);
		if(pid == playerid) {
			format(string, sizeof(string), "*** UFR Admin: You changed your car's speed to %fKm/h", floatround(1.61*floatsqroot(floatpower(floatabs(x * speed / 140), 2.0) + floatpower(floatabs(y * speed / 140), 2.0) + floatpower(floatabs(y * speed / 140), 2.0)) * 100.3));
	    } else {
			format(string, sizeof(string), "*** UFR Admin: Admin %s (ID: %d) changed your car's speed to %dKm/h", PlayerName(playerid), playerid, floatround(1.61*floatsqroot(floatpower(floatabs(x * speed / 140), 2.0) + floatpower(floatabs(y * speed / 140), 2.0) + floatpower(floatabs(y * speed / 140), 2.0)) * 100.3));
			SendClientMessage(pid,COLOR_YELLOW,string);
			format(string, sizeof(string), "*** UFR Admin: You changed %s's (ID: %d) car's speed to %fKm/h", PlayerName(pid), pid, floatround(1.61*floatsqroot(floatpower(floatabs(x * speed / 140), 2.0) + floatpower(floatabs(y * speed / 140), 2.0) + floatpower(floatabs(y * speed / 140), 2.0)) * 100.3));
		}
		SendClientMessage(playerid,COLOR_YELLOW,string);
	} else {
		SendClientMessage(playerid,COLOR_YELLOW,"You must be admin use this command.");
	}
	return 1;
}