public void UpdateVehiclePosition(VehicleMovementData vehicleModel, Optional <RemotePlayer> player) { Vector3 remotePosition = vehicleModel.Position; Vector3 remoteVelocity = vehicleModel.Velocity; Quaternion remoteRotation = vehicleModel.Rotation; Vector3 angularVelocity = vehicleModel.AngularVelocity; Vehicle vehicle = null; SubRoot subRoot = null; Optional <GameObject> opGameObject = NitroxEntity.GetObjectFrom(vehicleModel.Id); if (opGameObject.HasValue) { GameObject gameObject = opGameObject.Value; vehicle = gameObject.GetComponent <Vehicle>(); subRoot = gameObject.GetComponent <SubRoot>(); MultiplayerVehicleControl mvc = null; if (subRoot != null) { mvc = subRoot.gameObject.EnsureComponent <MultiplayerCyclops>(); subRoot.GetComponent <LiveMixin>().health = vehicleModel.Health; } else if (vehicle != null) { SeaMoth seamoth = vehicle as SeaMoth; Exosuit exosuit = vehicle as Exosuit; if (seamoth) { mvc = seamoth.gameObject.EnsureComponent <MultiplayerSeaMoth>(); } else if (exosuit) { mvc = exosuit.gameObject.EnsureComponent <MultiplayerExosuit>(); if (vehicleModel.GetType() == typeof(ExosuitMovementData)) { ExosuitMovementData exoSuitMovement = (ExosuitMovementData)vehicleModel; mvc.SetArmPositions(exoSuitMovement.LeftAimTarget, exoSuitMovement.RightAimTarget); } else { Log.Error($"{nameof(Vehicles)}: Got exosuit vehicle but no ExosuitMovementData"); } } vehicle.GetComponent <LiveMixin>().health = vehicleModel.Health; } if (mvc != null) { mvc.SetPositionVelocityRotation(remotePosition, remoteVelocity, remoteRotation, angularVelocity); mvc.SetThrottle(vehicleModel.AppliedThrottle); mvc.SetSteeringWheel(vehicleModel.SteeringWheelYaw, vehicleModel.SteeringWheelPitch); } } if (player.HasValue) { RemotePlayer playerInstance = player.Value; playerInstance.SetVehicle(vehicle); playerInstance.SetSubRoot(subRoot); playerInstance.SetPilotingChair(subRoot?.GetComponentInChildren <PilotingChair>()); playerInstance.AnimationController.UpdatePlayerAnimations = false; } }
public void UpdateVehiclePosition(VehicleMovementData vehicleModel, Optional <RemotePlayer> player) { Optional <GameObject> opGameObject = NitroxEntity.GetObjectFrom(vehicleModel.Id); Vehicle vehicle = null; SubRoot subRoot = null; if (opGameObject.HasValue) { Rocket rocket = opGameObject.Value.GetComponent <Rocket>(); vehicle = opGameObject.Value.GetComponent <Vehicle>(); subRoot = opGameObject.Value.GetComponent <SubRoot>(); MultiplayerVehicleControl mvc = null; if (subRoot) { mvc = subRoot.gameObject.EnsureComponent <MultiplayerCyclops>(); } else if (vehicle) { if (vehicle.docked) { Log.Debug($"For vehicle {vehicleModel.Id} position update while docked, will not execute"); return; } switch (vehicle) { case SeaMoth seamoth: { mvc = seamoth.gameObject.EnsureComponent <MultiplayerSeaMoth>(); break; } case Exosuit exosuit: { mvc = exosuit.gameObject.EnsureComponent <MultiplayerExosuit>(); if (vehicleModel is ExosuitMovementData exoSuitMovement) { mvc.SetArmPositions(exoSuitMovement.LeftAimTarget.ToUnity(), exoSuitMovement.RightAimTarget.ToUnity()); } else { Log.Error($"{nameof(Vehicles)}: Got exosuit vehicle but no ExosuitMovementData"); } break; } } } else if (rocket) { rocket.transform.position = vehicleModel.Position.ToUnity(); rocket.transform.rotation = vehicleModel.Rotation.ToUnity(); } if (mvc) { mvc.SetPositionVelocityRotation( vehicleModel.Position.ToUnity(), vehicleModel.Velocity.ToUnity(), vehicleModel.Rotation.ToUnity(), vehicleModel.AngularVelocity.ToUnity() ); mvc.SetThrottle(vehicleModel.AppliedThrottle); mvc.SetSteeringWheel(vehicleModel.SteeringWheelYaw, vehicleModel.SteeringWheelPitch); } } if (player.HasValue) { RemotePlayer playerInstance = player.Value; playerInstance.SetVehicle(vehicle); playerInstance.SetSubRoot(subRoot); playerInstance.SetPilotingChair(subRoot?.GetComponentInChildren <PilotingChair>()); playerInstance.AnimationController.UpdatePlayerAnimations = false; } }