Place vehicle righter
#5

Well, excuse me for my noobness, I rarely ask something for help unless I'm totally new in it.

I have this code which pulls the car towards the X,Y,Z coordinates (all constans are defined).
Код:
stock PullVehicleIntoDirection(vehicleid, Float:x, Float:y, Float:z, Float:speed)//Thanks to Miguel for supplying me with this function, I have edited it a bit
{
	new
        Float:distance,
        Float:vehicle_pos[3];

    GetVehiclePos(vehicleid, vehicle_pos[0], vehicle_pos[1], vehicle_pos[2]);
	#if defined USE_SMOOTH_TURNS
	new Float: oz = atan2VehicleZ(vehicle_pos[0], vehicle_pos[1], x, y);
	new Float: vz;
	GetVehicleZAngle(vehicleid, vz);
	if(oz < vz-180) oz = oz+360;
	if(vz < oz-180) vz = vz+360;
	new Float: cz = floatabs(vz - oz);
	#else
	SetVehicleZAngle(vehicleid, atan2VehicleZ(vehicle_pos[0], vehicle_pos[1], x, y));
	#endif
    x -= vehicle_pos[0];
    y -= vehicle_pos[1];
    z -= vehicle_pos[2];
    #if defined DEPRECATE_Z
    distance = floatsqroot((x * x) + (y * y));
    x = (speed * x) / distance;
    y = (speed * y) / distance;
    GetVehicleVelocity(vehicleid, vehicle_pos[0], vehicle_pos[0], z);
    #else
    z+=0.11;
    distance = floatsqroot((x * x) + (y * y) + (z * z));
    x = (speed * x) / distance;
    y = (speed * y) / distance;
    z = (speed * z) / distance;
    #endif
	#if defined USE_SMOOTH_TURNS
	if(cz > 0)
 	{
		new Float: fz = cz*0.0015;
		if(vz < oz) SetVehicleAngularVelocity(vehicleid, 0.0, 0.0, fz);
		if(vz > oz) SetVehicleAngularVelocity(vehicleid, 0.0, 0.0, -fz);
	}
	#endif
    SetVehicleVelocity(vehicleid, x, y, z);
}

forward Float:atan2VehicleZ(Float:Xb,Float:Yb,Float:Xe,Float:Ye);// Dunno how to name it...
stock Float:atan2VehicleZ(Float:Xb,Float:Yb,Float:Xe,Float:Ye)
{
	new Float:a = floatabs(360.0 - atan2( Xe-Xb,Ye-Yb));
	if(360 > a > 180)return a;
	return a-360.0;
}
Well I knew it wrong, I should know the coordinates before the calculating begins. Or not?

The only thing I've succesfully made with the code you posted is presented with the "not like that" picture. I'd like to make something like the picture "like that". The arrows are preseting the directions where the cars are moving actually.

http://imagerz.com/QFdDX1VSBl8
Reply


Messages In This Thread
Place vehicle righter - by Reynolds - 27.04.2012, 14:48
Re: Place vehicle righter - by Finn - 27.04.2012, 15:01
Re: Place vehicle righter - by Reynolds - 27.04.2012, 15:14
Re: Place vehicle righter - by Finn - 27.04.2012, 15:30
Re: Place vehicle righter - by Reynolds - 27.04.2012, 16:25
Re: Place vehicle righter - by Finn - 27.04.2012, 17:06
Re: Place vehicle righter - by Reynolds - 27.04.2012, 17:32
Re: Place vehicle righter - by Finn - 27.04.2012, 18:43
Re: Place vehicle righter - by Reynolds - 27.04.2012, 19:11

Forum Jump:


Users browsing this thread: 2 Guest(s)