MPProjectPointOnVehicle goes wrong!
#1

Hi guys,

I'm using JernejL MathPlugin. I'm trying to use MPProjectPointOnVehicle function, but it doesn't do what it should.

pawn Код:
COMMAND:blablabla(playerid, params[])
{
    if( isnull( params ) ) return SendClientMessage( playerid, 0xFF0000FF, "wrong, bla bla bla" );
    new
        Float:x,
        Float:y,
        Float:z,
        Float:a,
        car
    ;
    GetPlayerFacingAngle( playerid, a );
    GetPlayerPos( playerid, x, y, z );
    if( IsPlayerInAnyVehicle( playerid ) )
    {
        DestroyVehicle( GetPlayerVehicleID( playerid ) );
        RemovePlayerFromVehicle( playerid );
    }
    car = CreateVehicle( strval( params ), x, y, z, a, 6, 6, 1000 );
    PutPlayerInVehicle( playerid, car, 0 );

    /*new
        obj = CreateObject( 325, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 )
    ;
    AttachObjectToVehicle( obj, car, 0.0, -2.89, 0.0, 0.0, 0.0, 0.0 );*/

    new
        Float:result[ 3 ]
    ;
    MPProjectPointOnVehicle( car, 0.0, -2.89, 0.0, result[ 0 ], result[ 1 ], result[ 2 ], 1 );
    CreateObject( 325, result[ 0 ], result[ 1 ], result[ 2 ], 0.0, 0.0, 0.0 );
    return 1;
}
Using AttachObjectToVehicle is perfect:


But MPProjectPointOnvehicle doesn't work(object is in different pos in different angles)


Please, help someone to fix this !

Thanks!
Reply
#2

The calculation you have done is wrong maybe. Try to take them in opp. sides.
Reply
#3

MPProjectPointOnVehicle doesn't work correctly for a vehicle that's just been spawned, so just introduce a timer:

pawn Код:
forward MPTimer(Vid, Float:x, Float:y, Float:z);

COMMAND:test(playerid, params[])
{
    if( isnull( params ) ) return SendClientMessage( playerid, 0xFF0000FF, "wrong, bla bla bla" );
    new
        Float:x,
        Float:y,
        Float:z,
        Float:a,
        car
    ;
    GetPlayerFacingAngle( playerid, a );
    GetPlayerPos( playerid, x, y, z );
    if( IsPlayerInAnyVehicle( playerid ) )
    {
        DestroyVehicle( GetPlayerVehicleID( playerid ) );
        RemovePlayerFromVehicle( playerid );
    }
    car = CreateVehicle( strval( params ), x, y, z, a, 6, 6, 1000 );
    PutPlayerInVehicle( playerid, car, 0 );
    SetTimerEx("MPTimer", 100, false, "ifff", car, x, y, z);
    return 1;
}

public MPTimer(Vid, Float:x, Float:y, Float:z)
{
    /*new
        obj = CreateObject( 325, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 )
    ;
    AttachObjectToVehicle( obj, car, 0.0, -2.89, 0.0, 0.0, 0.0, 0.0 );*/

    new
        Float:result[ 3 ]
    ;
    MPProjectPointOnVehicle( Vid, 0.0, 2.89, 0.0, result[0], result[1], result[2]);
    CreateObject( 325, result[0]+x, result[1]+y, result[2]+z, 0.0, 0.0, 0.0 );
    return 1;
}
Reply
#4

It works fine - thanks a lot .
Reply
#5

Responding to your PM:

It does not take "angles"!!! It project a point on the vehicle in vehicle's world space.
Reply
#6

What the hell, again . It returns different coords, if I'm in vehicle or not!! If I'm in vehicle, the coords is perfect.

pawn Код:
new
    Float:offsetPos[ 6 ]
;
GetVehicleModelInfo( GetVehicleModel( vehicleid ), VEHICLE_MODEL_INFO_SIZE, offsetPos[ 0 ], offsetPos[ 1 ], offsetPos[ 2 ] );
printf( "GetVehicleModelInfo: %f, %f, %f", offsetPos[ 0 ], offsetPos[ 1 ], offsetPos[ 2 ] );
offsetPos[ 1 ] = offsetPos[ 1 ] / 2.0;
//offsetPos[ 1 ] = -offsetPos[ 1 ];

SetTimerEx( "fakeris", 200, false, "if", vehicleid, offsetPos[ 1 ] );
MPProjectPointOnVehicle( vehicleid, 0.0, offsetPos[ 1 ], 0.0, offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ], 1 );
printf( "MPProjectPointOnVehicle: %f, %f, %f", offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ] );

CreateObject( 325, offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ], 0.0, 0.0, 0.0 );
Reply
#7

then pre-prepare coords incase you exitted the vehicle or something?
Reply
#8

Quote:
Originally Posted by JernejL
Посмотреть сообщение
then pre-prepare coords incase you exitted the vehicle or something?
Do you mean, when player exits vehicle, I get(using MPProjectPointOnVehicle) and save coords in to a variable? But what if vehicle will move when there is no player in it(someone will "push" it)?
Reply
#9

How are you getting the vehicle id?
When the player is in the vehicle it is easy using GetPlayerVehicleID(playerid)
But do you have a way to tell which vehicle id to use when the player is not in a vehicle?
Reply
#10

Thanks for reply, here it is:

Код:
// command
COMMAND:cmd(playerid, params[])
{
	IsPlayerNearVehicleBoot( playerid, GetPlayerVehicleID( playerid ) );
	return 1;
}
// another part
new
	Float:mPos[ 3 ]
;
for( new i; i < MAX_VEHICLES; i++ )
{
    GetVehiclePos( i, mPos[ 0 ], mPos[ 1 ], mPos[ 2 ] );
    if( IsPlayerInRangeOfPoint( playerid, 3.5, mPos[ 0 ], mPos[ 1 ], mPos[ 2 ] ) )
    {
		function( playerid, i );
		break;
	}
}

// another part
stock function( playerid, vehicleid )
{
	new
		Float:offsetPos[ 6 ]
	;
	GetVehicleModelInfo( GetVehicleModel( vehicleid ), VEHICLE_MODEL_INFO_SIZE, offsetPos[ 0 ], offsetPos[ 1 ], offsetPos[ 2 ] );
	printf( "GetVehicleModelInfo: %f, %f, %f", offsetPos[ 0 ], offsetPos[ 1 ], offsetPos[ 2 ] );
	offsetPos[ 1 ] = offsetPos[ 1 ] / 2.0;
	//offsetPos[ 1 ] = -offsetPos[ 1 ];

	MPProjectPointOnVehicle( vehicleid, 0.0, offsetPos[ 1 ], 0.0, offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ], 1 );
	printf( "MPProjectPointOnVehicle: %f, %f, %f", offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ] );

	CreateObject( 325, offsetPos[ 3 ], offsetPos[ 4 ], offsetPos[ 5 ], 0.0, 0.0, 0.0 );
	return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)