GetNearestDynObject - doing the opposite
#8

Quote:
Originally Posted by [MG]Dimi
Посмотреть сообщение
Hm try your original code but change it get you the furthest object, it might return you correct one
I need the nearest object, so doing that would be a waste of time, don't you think?

EDIT: I tried doing it anyways, since there's nothing I can do until this is resolved. It DOES return the FARTHEST object with the function below:

pawn Код:
stock GetNearestDynObject(playerid)
{
    new
        Float: px, Float: py, Float: pz,
        currentobject = -1,
        Float:distance = -1
    ;
    GetPlayerPos( playerid, px, py, pz );

    for( new index = 0; index < CountDynamicObjects(); index++ )
    {
        if ( !IsValidDynamicObject( index ) ) continue;

        new
            Float:ox,
            Float:oy,
            Float:oz
        ;
        GetDynamicObjectPos( index, ox, oy, oz );

        new Float:odist = floatsqroot(
            floatpower( floatabs( floatsub( ox, px ) ), 2.0 ) -
            floatpower( floatabs( floatsub( oy, py ) ), 2.0 ) -
            floatpower( floatabs( floatsub( oz, pz ) ), 2.0 )
        );

        if ( currentobject == -1 )
        {
            currentobject = index;
            distance = odist;
        }
        else if ( odist > distance )
        {
            currentobject = index;
            distance = odist;
        }
    }
    return currentobject;
}
Reply


Messages In This Thread
GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 21:24
Re: GetNearestDynObject - doing the opposite - by Babul - 17.02.2013, 21:52
Re: GetNearestDynObject - doing the opposite - by Stylock - 17.02.2013, 22:01
Re: GetNearestDynObject - doing the opposite - by [MG]Dimi - 17.02.2013, 22:10
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:13
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:18
Re: GetNearestDynObject - doing the opposite - by [MG]Dimi - 17.02.2013, 22:19
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:20
Re: GetNearestDynObject - doing the opposite - by Scenario - 17.02.2013, 22:32
Re: GetNearestDynObject - doing the opposite - by Babul - 17.02.2013, 22:43

Forum Jump:


Users browsing this thread: 3 Guest(s)