Quantcast

Jump to content

» «
Photo

Closest vehicle in facing direction

  • This topic is locked This topic is locked
7 replies to this topic
Braveheartuk
  • Braveheartuk

    Player Hater

  • Members
  • Joined: 02 Jun 2012

#1

Posted 30 July 2012 - 12:21 AM Edited by Braveheartuk, 30 July 2012 - 12:30 AM.

How would I go about getting the closest vehicle/ped from the direction I'm facing as opposed to anywhere around my location ( Vehicle Vehicle = World.GetClosestVehicle(Player.Character.Position, 5.0f))?

Also how would I check if a player is stood next to a vehicle's driver side door?

LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#2

Posted 13 June 2014 - 05:34 PM Edited by LetsPlayOrDy, 13 June 2014 - 05:35 PM.

How would I go about getting the closest vehicle/ped from the direction I'm facing as opposed to anywhere around my location ( Vehicle Vehicle = World.GetClosestVehicle(Player.Character.Position, 5.0f))?

Also how would I check if a player is stood next to a vehicle's driver side door?

 

If the vehicle is looking your direction also or if you can see the vehicle?


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#3

Posted 13 June 2014 - 06:11 PM

Which direction? The camera or the player peds direction?

Rugz007
  • Rugz007

    Scripters ... roll out !

  • Members
  • Joined: 19 Apr 2014
  • India

#4

Posted 13 June 2014 - 06:19 PM

I think he is teliing camera and you can see the vehicle

LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#5

Posted 13 June 2014 - 06:22 PM Edited by LordOfTheBongs, 13 June 2014 - 07:20 PM.

Camera direction u can check if on screen but for more precise I would try this, also use this way for peds direction...
 

bool IsVehicleInPlayerDirection(int searchTime, out Vehicle vehicle)
{
    vehicle = null;
    int time = Game.GameTime; Vector3 endPosition = Player.Character.Position;
    for (Vector3 p = endPosition; Game.GameTime - time < searchTime; p += Player.Character.Direction)
    {
        endPosition = p.ToGround();
        Vehicle v = World.GetClosestVehicle(endPosition, 2f);
        if (Game.Exists(v))
        {
            //found vehicle in player direction
            vehicle = v;
            return true;
        }
        Wait(0);//so u dont block ScriptThread
    }

    //for debug so u can tweak the search time if no car is found
    float distanceSearched = Player.Character.Position.DistanceTo(endPosition);
    Game.DisplayText("Distance Searched: " + distanceSearched.ToString());

    return false;
}

just note this method wont return until the search time ends, or a car is found so maybe not the best way and u may have to mess with the code to get this to work in a way that works with your script... but ur most likely going to have to loop a straight line from your ped to know where cars are and that is expensive as they say


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#6

Posted 13 June 2014 - 07:25 PM Edited by InfamousSabre, 13 June 2014 - 07:25 PM.

He asked this question way back in 2012.. o.O I doubt he'll be back here any time soon.
LetsPlayOrDy necroing HxC today..


LetsPlayOrDy
  • LetsPlayOrDy

    Too fast for ya

  • Members
  • Joined: 24 Aug 2013
  • United-States

#7

Posted 13 June 2014 - 07:36 PM Edited by LetsPlayOrDy, 13 June 2014 - 07:57 PM.

He asked this question way back in 2012.. o.O I doubt he'll be back here any time soon.
LetsPlayOrDy necroing HxC today..

 

Actually I didn't even see the date. I was just looking at un-replied-to posts. Now I see the dates and I feel dumb XD

 

Edit: Actually with all of those posts I bumped, I didn't even see the date :/ (Sorry about that @Silent )


Silent
  • Silent

    Moderating Cookie Monster

  • Feroci Racing
  • Joined: 01 Feb 2010
  • Poland
  • Most Helpful [GTA] 2013
    Most Helpful [Modding] 2013
    Most Talented [Modding] 2013
    Best Map 2013 "ViceCityStories PC Edition"
    Best Vehicle 2013 "III Aircraft"
    Most Helpful [Modding] 2012
    Modder of the Year 2012

#8

Posted 15 June 2014 - 01:54 PM

He asked this question way back in 2012.. o.O I doubt he'll be back here any time soon.


This.

  • Wiebrendh likes this




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users