2
0
Fork 0
mirror of https://github.com/GTA-ASM/SanAndreasUnity synced 2025-02-25 19:57:16 +00:00

when entering/exiting car, don't call API which moves ped in/out of vehicle, but instead send input to ped

This commit is contained in:
in0finite 2021-09-12 04:08:19 +02:00
parent f7327d9409
commit c71b7f41bc
2 changed files with 30 additions and 14 deletions
Assets/Scripts/Behaviours/Ped

View file

@ -178,15 +178,19 @@ namespace SanAndreasUnity.Behaviours
.FirstOrDefault ();
if (closestfreeSeat != null) {
// check if it is in range
if (closestfreeSeat.tr.Distance (this.transform.position) < this.MyPed.EnterVehicleRadius) {
// the seat is in range
this.MyPed.EnterVehicle (vehicle, closestfreeSeat.sa);
// check if we would enter this seat on attempt
var vehicleThatPedWouldEnter = this.MyPed.GetVehicleThatPedWouldEnterOnAttempt();
if (vehicleThatPedWouldEnter.vehicle == vehicle && vehicleThatPedWouldEnter.seatAlignment == closestfreeSeat.sa)
{
// we would enter this seat
// go ahead and enter it
this.MyPed.OnSubmitPressed();
return;
} else {
// the seat is not in range
// move towards this seat
// we would not enter this seat - it's not close enough, or maybe some other seat (occupied one) is closer
// move toward the seat
targetPos = closestfreeSeat.tr.position;
currentStoppingDistance = 0.1f;
currentStoppingDistance = 0.01f;
}
}
@ -194,7 +198,8 @@ namespace SanAndreasUnity.Behaviours
// target player is not in vehicle, and ours is
// exit the vehicle
this.MyPed.ExitVehicle ();
this.MyPed.OnSubmitPressed();
return;
}

View file

@ -95,17 +95,28 @@ namespace SanAndreasUnity.Behaviours
}
public (Vehicle vehicle, Vehicle.SeatAlignment seatAlignment) GetVehicleThatPedWouldEnterOnAttempt()
{
var vehicle = this.FindVehicleInRange();
if (null == vehicle)
return default;
var seatAlignment = vehicle.GetSeatAlignmentOfClosestSeat(this.transform.position);
if (seatAlignment == Vehicle.SeatAlignment.None)
return default;
return (vehicle, seatAlignment);
}
public Vehicle TryEnterVehicleInRange ()
{
var vehicle = this.FindVehicleInRange ();
if (null == vehicle)
var vehicleAndSeatAlignment = this.GetVehicleThatPedWouldEnterOnAttempt();
if (null == vehicleAndSeatAlignment.vehicle)
return null;
var seat = vehicle.GetSeatAlignmentOfClosestSeat(this.transform.position);
this.EnterVehicle(vehicleAndSeatAlignment.vehicle, vehicleAndSeatAlignment.seatAlignment);
this.EnterVehicle(vehicle, seat);
return vehicle;
return vehicleAndSeatAlignment.vehicle;
}
}