Place vehicle righter
#1

Hi,

Well I'm using the GPS plugin by Gamer_Z to make a system with NPCs. My final goal would be to create an AI NPC system. The problem is: all of the nodes in this plugin are placed on the middle of the road. I need to place them a bit righter so the car could be in the lane. But of course this won't work with X,Y,Z manipulating because the roads aren't going to one direction.

I have the ZAngle set when the vehicle is turning towards the point if it helps.

I'm stuck with it, any suggestions how could I fix this?
Reply
#2

If you know the direction (angle) and position, what's the big deal?
Reply
#3

Well I'm not good at trigometry, I know it's not that complex, but I have no idea how to do it.
Reply
#4

pawn Код:
// Turn the angle to point right (-90 degrees)
angle = ((angle - 90.0) < 0.0) ? (360.0 + (angle - 90.0)) : (angle - 90.0);

// Move the coordinades towards the angle
x += (distance * floatsin(-angle, degrees));
y += (distance * floatcos(-angle, degrees));
Reply
#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
#6

That is not the place you set the vehicle's position, you are only setting the velocity and angle of it with that function.
Reply
#7

What I actually want is shown on the first figure.

http://imagerz.com/QFdDX1VSBl8

Here. The road connecting nodes are on the middle of the road, but it'd be pretty interesting to see an NPC driving there instead in the lane. That's why I'd like to set the coordinates some way so the coordinates the vehicles are pulled are in the lane, not on the road centerline.
Reply
#8

I understood what you want from the first post of this thread.

You have to spawn the vehicle on the right lane and after that do what you want with the velocity of it.
Reply
#9

Quote:
Originally Posted by Finn
Посмотреть сообщение
I understood what you want from the first post of this thread.

You have to spawn the vehicle on the right lane and after that do what you want with the velocity of it.
Yes, that's correct. Is there any way to do it without knowing anything else except the function above?

nvm, I figured it out.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)