private void SetRudderAnglesFromCmd(AdvancedShipController controller, VehicleCmd cmd) { var rudders = controller.rudders; for (int i = 0; i < rudders.Count; ++i) { rudders[i].Angle = cmd.Steerables[i].Ship.Angle; } }
private void SetWheelAnglesFromCmd(VehicleAbstractController controller, VehicleCmd cmd) { var wheelCount = controller.WheelCount; for (int i = 0; i < wheelCount; ++i) { var wheel = controller.GetWheel(i); wheel.wheelCollider.steerAngle = cmd.Steerables[i].Car.Angle; } }
private static VehicleDynamicState GetStateFromCmd(VehicleCmd cmd) { var state = new VehicleDynamicState() { Position = cmd.Body.Position.ShiftedVector3(), Rotation = cmd.Body.Rotation, LinearVelocity = cmd.Body.LinearVelocity, AngularVelocity = cmd.Body.AngularVelocity, IsSleeping = cmd.Body.IsSleeping, Crashed = false,//state 'crashed' is dertermined by server. }; return(state); }
private void SetWheelPosesFromCmd(VehicleAbstractController controller, VehicleCmd cmd) { var wheelCount = controller.WheelCount; for (int i = 0; i < wheelCount; ++i) { var wheel = controller.GetWheel(i); var wd = controller.GetWheelData(i); wheel.wheelTransform.localPosition = cmd.Steerables[i].Car.Position; wheel.wheelTransform.localRotation = cmd.Steerables[i].Car.Rotation; // wd.Grounded = cmd.Steerables[i].Car.Grounded; // wd.GroundedOnTerrain = cmd.Steerables[i].Car.Grounded; } }
public UnityVehicleCmdGenerator(UserInputManager.Lib.UserInputManager manager) { _lastCmd = new VehicleCmd(); _inputManager = manager; // 界面不会影响车辆控制 var keyhandler = new KeyHandler(Layer.Ui, BlockType.None); _inputManager.RegisterKeyhandler(keyhandler); keyhandler.BindKeyAction(UserInputKey.MoveVertical, data => _lastCmd.MoveVertical = data.Axis); keyhandler.BindKeyAction(UserInputKey.MoveHorizontal, data => _lastCmd.MoveHorizontal = data.Axis); keyhandler.BindKeyAction(UserInputKey.VehicleSpeedUp, data => _lastCmd.IsSpeedup = true); keyhandler.BindKeyAction(UserInputKey.VehicleBrake, data => _lastCmd.IsHandbrake = true); keyhandler.BindKeyAction(UserInputKey.VehicleHorn, data => _lastCmd.IsHornOn = true); keyhandler.BindKeyAction(UserInputKey.VehicleLeftShift, data => _lastCmd.IsLeftShift = true); keyhandler.BindKeyAction(UserInputKey.VehicleRightShift, data => _lastCmd.IsRightShift = true); keyhandler.BindKeyAction(UserInputKey.VehicleStunt, data => _lastCmd.IsStunt = true); }
public IVehicleCmd GeneratorVehicleCmd(int currentSimulationTime) { if (currentSimulationTime <= 0 || _lastCmdExecuteTime >= currentSimulationTime) { return(null); } var vehicleCmd = VehicleCmd.Allocate(); { vehicleCmd.Seq = _seq++; vehicleCmd.CmdSeq = vehicleCmd.Seq; }; _lastCmd.CopyInputTo(vehicleCmd); _lastCmd.ResetInput(); vehicleCmd.ExecuteTime = currentSimulationTime; vehicleCmd.Seq = currentSimulationTime; _lastCmdExecuteTime = currentSimulationTime; if (firstSet) { autoGo = GameObject.Find("VehicleCmdAutoGenerator"); firstSet = false; if (autoGo != null) { autoGo.SetActive(false); } } if (autoGo != null && autoGo.activeSelf) { vehicleCmd.MoveVertical = 1; vehicleCmd.MoveHorizontal = 0.6f; } return(vehicleCmd); }
public static VehicleDynamicState MoveToState(VehicleCommonController controller, VehicleCmd cmd) { return(MoveToStateInternal(controller, GetStateFromCmd(cmd))); }
public static ReusableList <IVehicleCmd> FromProtoBuf(VehicleCmdMessage message) { ReusableList <IVehicleCmd> list = ReusableList <IVehicleCmd> .Allocate(); var count = message.VehicleCmdList.Count; for (int i = 0; i < count; ++i) { var item = message.VehicleCmdList[i]; var cmd = VehicleCmd.Allocate(); { cmd.Seq = item.Seq; cmd.PlayerId = item.PlayerId; cmd.VehicleId = item.VehicleId; cmd.MoveHorizontal = item.MoveHorizontal; cmd.MoveVertical = item.MoveVertical; cmd.IsSpeedup = item.IsSpeedup; cmd.IsHandbrake = item.IsHandbrake; cmd.IsHornOn = item.IsHornOn; cmd.IsStunt = item.IsStunt; cmd.IsLeftShift = item.IsLeftShift; cmd.IsRightShift = item.IsRightShift; cmd.ExecuteTime = item.ExecuteTime; cmd.CmdSeq = item.CmdSeq; cmd.Body.Position = Vector3Converter.ProtobufToUnityVector3(item.Body.Position).ShiftedToFixedVector3(); cmd.Body.Rotation = Vector3Converter.ProtobufToUnityQuaternion(item.Body.Rotation); // cmd.Body.Body2WorldPosition = Vector3Converter.ProtobufToUnityVector3(item.Body.Body2WorldPosition); // cmd.Body.Body2WorldRotation = Vector3Converter.ProtobufToUnityQuaternion(item.Body.Body2WorldRotation); cmd.Body.LinearVelocity = Vector3Converter.ProtobufToUnityVector3(item.Body.LinearVelocity); cmd.Body.AngularVelocity = Vector3Converter.ProtobufToUnityVector3(item.Body.AngularVelocity); // cmd.Body.ContactCount = item.Body.ContactCount; cmd.Body.Crashed = item.Body.Crashed; cmd.Body.IsSleeping = item.Body.IsSleeping; var carSteerableCount = item.CarSteerables.Count; for (int j = 0; j < carSteerableCount; ++j) { var steerable = cmd.Steerables[j].Car; var steerableItem = item.CarSteerables[j]; steerable.Position = Vector3Converter.ProtobufToUnityVector3(steerableItem.Position); steerable.Rotation = Vector3Converter.ProtobufToUnityQuaternion(steerableItem.Rotation); steerable.Angle = steerableItem.Angle; // steerable.Grounded = steerableItem.Grounded; // steerable.GroundedOnTerrain = steerableItem.GroundedOnTerrain; // steerable.ColliderSteerAngle = steerableItem.ColliderSteerAngle; // steerable.SteerAngle = steerableItem.SteerAngle; // steerable.MotorTorque = steerableItem.MotorTorque; // // steerable.SuspensionDistance = steerableItem.SuspensionDistance; // steerable.SuspensionSpring = steerableItem.SuspensionSpring; // steerable.SuspensionTargetPosition = steerableItem.SuspensionTargetPosition; // // steerable.SprungMass = steerableItem.SprungMass; // steerable.ForceDistance = steerableItem.ForceDistance; // // steerable.AngularVelocity = steerableItem.AngularVelocity; // steerable.AngularPosition = steerableItem.AngularPosition; // steerable.RotationAngle = steerableItem.RotationAngle; // // steerable.RotationSpeed = steerableItem.RotationSpeed; // steerable.CorrectedRotationSpeed = steerableItem.CorrectedRotationSpeed; // steerable.Jounce = steerableItem.Jounce; // // steerable.TireLowSideSpeedTimers = steerableItem.TireLowSideSpeedTimers; // steerable.TireLowforwardSpeedTimers = steerableItem.TireLowforwardSpeedTimers; // // steerable.Grounded = steerableItem.Grounded; // steerable.Point = Vector3Converter.ProtobufToUnityVector3(steerableItem.Point); // steerable.Normal = Vector3Converter.ProtobufToUnityVector3(steerableItem.Normal); // steerable.ForwardDir = Vector3Converter.ProtobufToUnityVector3(steerableItem.ForwardDir); // steerable.SidewaysDir = Vector3Converter.ProtobufToUnityVector3(steerableItem.SidewaysDir); // steerable.Force = steerableItem.Force; // // steerable.ForwardSlip = steerableItem.ForwardSlip; // steerable.SidewaysSlip = steerableItem.SidewaysSlip; cmd.Steerables[j].Car = steerable; } var shipSteerableCount = item.ShipSteerables.Count; for (int j = 0; j < shipSteerableCount; ++j) { var steerable = cmd.Steerables[j].Ship; var steerableItem = item.ShipSteerables[j]; steerable.Angle = steerableItem.Angle; // steerableItem.Rpm = steerableItem.Rpm; // steerableItem.SpinVelocity = steerableItem.SpinVelocity; // steerableItem.Submerged = steerableItem.Submerged; cmd.Steerables[j].Ship = steerable; } if (carSteerableCount > shipSteerableCount) { cmd.VehicleType = (int)EVehicleType.Car; cmd.SteerableCount = carSteerableCount; } else { cmd.VehicleType = (int)EVehicleType.Ship; cmd.SteerableCount = shipSteerableCount; } }; list.Value.Add(cmd); } return(list); }