Jump to content

Why are Peds getting stuck in this loop when entering vehicles? [SOLVED]


ChillestDev

Recommended Posts

Video of pathfinding loop

 

Code I'm using:

private static bool pedEnteringVehicle = false;
        private static void WaitForPedToEnterVehicle()
        {
            var playerChar = Game.Player.Character;
            currentVehicle = playerChar.CurrentVehicle;

            if (Methods.enteringVehicle == false)
            {
                passenger.AlwaysKeepTask = true;
                Methods.PedEnterVehicle(currentVehicle, passenger);
                //pedEnteringVehicle = true;
            }
        }

//pedEnteringVehicle is another one time variable i was experimenting with

 

public static void PedEnterVehicle(Vehicle vehicle, Ped ped)
        {
            Random random = new Random();
            List<VehicleSeat> seats = new List<VehicleSeat>() { VehicleSeat.RightFront, VehicleSeat.LeftRear, VehicleSeat.RightRear };

            if (!Game.Player.Character.IsInVehicle()) return;

            if (vehicle != null && inVehicle == false && enteringVehicle == false)
            {
                VehicleSeat RandomSeat = seats[random.Next(0, seats.Count)];

                if (!vehicle.IsSeatFree(RandomSeat))
                {
                    RandomSeat = seats[random.Next(0, seats.Count)];
                }
                else
                {
                    ped.Task.EnterVehicle(vehicle, RandomSeat);
                }
            }
        }

 

Not been able to figure out why the Ped is getting stuck in this infinite pathfinding loop. Any help would be greatly appreciated!

 

EDIT: Thought I'd also add the PedVehicleChecks method which is being called regularly.

public static void PedVehicleChecks()
        {
            if (RideMission.activeMission == false) return;
            if (RideMission.passenger == null || !RideMission.passenger.Exists()) return;
            if (RideMission.currentVehicle == null) return;

            if (RideMission.passenger.IsInVehicle(RideMission.currentVehicle))
            {
                inVehicle = true;
            }

            if (!RideMission.passenger.IsInVehicle(RideMission.currentVehicle) && enteringVehicle == false)
            {
                inVehicle = false;
            }

            if (RideMission.passenger.IsGettingIntoVehicle)
            {
                enteringVehicle = true;
            }
            else { enteringVehicle = false; }
        }

 

EDIT 2: Upon posting this just figured, if its calling the PedEnterVehicle method whenever the Ped stops entering the vehicle, it's going to choose a new random seat causing the Ped to be confused. Will try this fix and remove this topic if this is the case.

 

SOLUTION: My second edit has corrected the issue! However I'll leave this up in the event someone else runs into this same issue.

Edited by ChillestDev
resolved
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.