Example #1
0
        public void ApplyTo(Vehicle vehicle, SpawnFlags spawnFlags = SpawnFlags.Default)
        {
            ApplyTo2(vehicle, spawnFlags.HasFlag(SpawnFlags.NoOccupants));

            if (!spawnFlags.HasFlag(SpawnFlags.NoPosition))
            {
                vehicle.PositionNoOffset = Position;
                vehicle.Heading          = Heading;
                vehicle.Rotation         = Rotation;
            }

            if (spawnFlags.HasFlag(SpawnFlags.SetRotation))
            {
                vehicle.Rotation = Rotation;
            }

            if (!spawnFlags.HasFlag(SpawnFlags.NoVelocity))
            {
                vehicle.Velocity = Velocity;
                vehicle.Speed    = Speed;
            }

            if (spawnFlags.HasFlag(SpawnFlags.NoWheels))
            {
                return;
            }

            for (int i = 0; i < WheelsRotations.Length; i++)
            {
                VehicleControl.SetWheelRotation(vehicle, i, FusionUtils.Wrap(WheelsRotations[i], -(float)Math.PI, (float)Math.PI));
                VehicleControl.SetWheelCompression(vehicle, i, WheelsCompressions[i]);
            }
        }
Example #2
0
        public void ApplyTo(Vehicle vehicle, SpawnFlags spawnFlags = SpawnFlags.Default, VehicleReplica nextReplica = default, float adjustedRatio = 0)
        {
            ApplyTo2(vehicle, spawnFlags.HasFlag(SpawnFlags.NoOccupants));

            if (nextReplica == default || nextReplica == null)
            {
                nextReplica = this;
            }

            if (!spawnFlags.HasFlag(SpawnFlags.NoPosition))
            {
                vehicle.PositionNoOffset = FusionUtils.Lerp(Position, nextReplica.Position, adjustedRatio);
                vehicle.Heading          = FusionUtils.Lerp(Heading, nextReplica.Heading, adjustedRatio);
                vehicle.Rotation         = FusionUtils.Lerp(Rotation, nextReplica.Rotation, adjustedRatio, -180, 180);
            }

            if (spawnFlags.HasFlag(SpawnFlags.SetRotation))
            {
                vehicle.Rotation = FusionUtils.Lerp(Rotation, nextReplica.Rotation, adjustedRatio, -180, 180);
            }

            if (!spawnFlags.HasFlag(SpawnFlags.NoVelocity))
            {
                vehicle.Velocity = FusionUtils.Lerp(Velocity, nextReplica.Velocity, adjustedRatio);
                vehicle.Speed    = FusionUtils.Lerp(Speed, nextReplica.Speed, adjustedRatio);
            }

            if (spawnFlags.HasFlag(SpawnFlags.NoWheels))
            {
                return;
            }

            for (int i = 0; i < WheelsRotations.Length; i++)
            {
                VehicleControl.SetWheelRotation(vehicle, i, FusionUtils.Lerp(WheelsRotations[i], nextReplica.WheelsRotations[i], adjustedRatio));
                VehicleControl.SetWheelCompression(vehicle, i, FusionUtils.Lerp(WheelsCompressions[i], nextReplica.WheelsCompressions[i], adjustedRatio));
            }
        }
Example #3
0
        public Vehicle Spawn(SpawnFlags spawnFlags, Vector3 position = default, float heading = default)
        {
            Vehicle veh = null;

            if (spawnFlags.HasFlag(SpawnFlags.CheckExists))
            {
                veh = World.GetClosestVehicle(Position, 1.0f, Model);
            }

            if (spawnFlags.HasFlag(SpawnFlags.NoPosition))
            {
                if (veh == null)
                {
                    veh = World.CreateVehicle(Model, position, heading);
                }
                else
                {
                    veh.Position = position;
                    veh.Heading  = heading;
                }
            }
            else
            {
                if (veh == null)
                {
                    veh = World.CreateVehicle(Model, Position, Heading);
                }
                else
                {
                    veh.Position = Position;
                    veh.Heading  = Heading;
                }
            }

            ApplyTo(veh, spawnFlags);

            return(veh);
        }
Example #4
0
        public VehicleReplica(Vehicle vehicle, SpawnFlags spawnFlags = SpawnFlags.Default) : base(vehicle)
        {
            EngineHealth   = vehicle.EngineHealth;
            EngineRunning  = vehicle.IsEngineRunning;
            PrimaryColor   = vehicle.Mods.PrimaryColor;
            SecondaryColor = vehicle.Mods.SecondaryColor;
            Livery         = vehicle.Mods.Livery;

            RPM  = vehicle.CurrentRPM;
            Gear = vehicle.CurrentGear;

            Throttle  = vehicle.ThrottlePower;
            Brake     = vehicle.BrakePower;
            Handbrake = VehicleControl.GetHandbrake(vehicle);

            SteeringAngle = vehicle.SteeringAngle;
            Lights        = vehicle.AreLightsOn;
            Headlights    = vehicle.AreHighBeamsOn;

            RunningDirection = vehicle.RunningDirection();

            WheelsRotations    = VehicleControl.GetWheelRotations(vehicle);
            WheelsCompressions = VehicleControl.GetWheelCompressions(vehicle);

            if (spawnFlags.HasFlag(SpawnFlags.NoOccupants))
            {
                return;
            }

            Occupants = new List <PedReplica>();

            foreach (Ped x in vehicle.Occupants)
            {
                Occupants.Add(new PedReplica(x));
            }
        }