// Component methods void OnEnable() { if (vehicle != null) { m_input = vehicle.GetComponent <VPStandardInput>(); m_settings = vehicle.GetComponent <VPSettingsSwitcher>(); } else { m_input = null; m_settings = null; } if (drivingAidsPanel != null) { drivingAidsPanel.ConfigureDefaults(); drivingAidsPanel.gameObject.SetActive(false); } // Switching steering mode when no gyro is available is not handled properly. // It may take a bit to the filter to catch up with the current acceleration. // // TO-DO: This should be deprecated and use a n-averaged value instead. m_acceleration = Input.acceleration; // Fallback to regular touch mode if no accelerometer nor gyro are present if (!SystemInfo.supportsAccelerometer && !SystemInfo.supportsGyroscope) { steeringMode = SteeringMode.Touch; } }
/// <summary> /// Set "Steering Mode Packet" /// </summary> public void SetSteeringMode(SteeringMode sm) { int n; byte[] buff; n = g_SCI2_TX_LEN; Tx_Buff[n++] = ( int )MessageType.SteeringModeChanged; //Type Of Data Tx_Buff[n++] = 6; //Packet Length buff = BitConverter.GetBytes(( int )sm); Tx_Buff[n++] = buff[0]; //dummy Tx_Buff[n++] = buff[1]; //dummy Tx_Buff[n++] = buff[2]; //dummy Tx_Buff[n++] = buff[3]; //dummy g_SCI2_TX_LEN = n; }
private float SteeringDecision(float leftSideDistance, float rightSideDistance, float leftDistance, float rightDistance, float frontMinDistance, bool frontContact, SteeringMode style) { float localSteeringAngle = steerAngle; float result = 0; switch (style) { case SteeringMode.Cautious: if (leftSideDistance == 0 && ((leftDistance == 0 && rightDistance > 0) || (rightDistance != 0 && leftDistance != 0 && leftDistance > rightDistance) || (leftDistance == 0 && frontMinDistance > 0) || (rightDistance > leftDistance && frontMinDistance > 0) || (frontContact==false && rightSideDistance > 0))) { result = (-1) * localSteeringAngle; //Debug.Log(" 1 leftDistance: " + leftDistance + ";rightDistance: " + rightDistance); } //nach rechts lenken //Kein "(leftSideDistance > 0) ||" weil kein Abdrengeln möglich sein soll if (rightSideDistance == 0 && ((rightDistance == 0 && leftDistance > 0) || (rightDistance != 0 && leftDistance != 0 && rightDistance > leftDistance) || (rightDistance == 0 && frontMinDistance > 0) || (leftDistance > rightDistance && frontMinDistance > 0) || (frontContact == false && leftSideDistance > 0))) { result = localSteeringAngle; } break; case SteeringMode.Tough: //steering //nach links lenken //Kein "(rightSideDistance > 0) ||" weil kein Abdrengeln möglich sein soll if (leftSideDistance == 0 && ((leftDistance == 0 && rightDistance > 0) || (rightDistance != 0 && leftDistance != 0 && leftDistance > rightDistance) || (leftDistance == 0 && frontMinDistance > 0) || (rightDistance > leftDistance && frontMinDistance > 0))) { result = (-1) * localSteeringAngle; //Debug.Log(" 1 leftDistance: " + leftDistance + ";rightDistance: " + rightDistance); } //nach rechts lenken //Kein "(leftSideDistance > 0) ||" weil kein Abdrengeln möglich sein soll if (rightSideDistance == 0 && ((rightDistance == 0 && leftDistance > 0) || (rightDistance != 0 && leftDistance != 0 && rightDistance > leftDistance) || (rightDistance == 0 && frontMinDistance > 0) || (leftDistance > rightDistance && frontMinDistance > 0))) { result = localSteeringAngle; } break; } return result; }
private float SteeringDecision(float leftSideDistance, float rightSideDistance, float leftDistance, float rightDistance, float frontMinDistance, bool frontContact, SteeringMode style) { //float localSteeringAngle = steerAngle; float localSteeringAngle = m_currentMaxSteerAngle; float result = 0; //keine Prozent sonder von 0 bis 1; float rightPercent = 1; float rightSidePercent = 1; float leftPercent = 1; float leftSidePercent = 1; if (frontContact && (frontMinDistance < 2)) { m_backwardDriving = true; } switch (style) { case SteeringMode.Cautious: //steer left if (leftSideDistance == 0 && ((leftDistance == 0 && rightDistance > 0) || (rightDistance != 0 && leftDistance != 0 && leftDistance > rightDistance) || (leftDistance == 0 && frontMinDistance > 0) || (rightDistance < leftDistance && frontMinDistance > 0 && rightDistance != 0) || (frontContact==false && rightSideDistance > 0))) //|| (leftDistance == 0 && frontMinDistance > 0) || (rightDistance > leftDistance && frontMinDistance > 0) || (frontContact==false && rightSideDistance > 0))) { if (!steerAbsolute) { //result = (-1) * localSteeringAngle; old if (frontMinDistance > 0) { result = (-1) * localSteeringAngle; //rightPercent = frontMinDistance / m_frontDistanceLength; //result = (-1) * localSteeringAngle * (1 - rightPercent); } else { if (rightSideDistance > 0) { rightSidePercent = rightSideDistance / m_leftRightSideDistanceLength; } if (rightDistance > 0) { rightPercent = rightDistance / m_leftRightDistanceLength; } if (rightSidePercent < rightPercent) { result = (-1) * localSteeringAngle * (1 - rightSidePercent); } else { result = (-1) * localSteeringAngle * (1 - rightPercent); } } } else { result = (-1) * localSteeringAngle; } } //steer right //Kein "(leftSideDistance > 0) ||" weil kein Abdrengeln möglich sein soll if (rightSideDistance == 0 && ((rightDistance == 0 && leftDistance > 0) || (rightDistance != 0 && leftDistance != 0 && rightDistance > leftDistance) || (rightDistance == 0 && frontMinDistance > 0) || (leftDistance < rightDistance && frontMinDistance > 0 && leftDistance != 0) || (frontContact == false && leftSideDistance > 0 ))) //|| (rightDistance == 0 && frontMinDistance > 0) || (leftDistance > rightDistance && frontMinDistance > 0) || (frontContact == false && leftSideDistance > 0))) { if (!steerAbsolute) { if (frontMinDistance > 0) { result = localSteeringAngle; //leftPercent = frontMinDistance / m_frontDistanceLength; //result = localSteeringAngle * (1 - leftPercent); } else { if (leftSideDistance > 0) { leftSidePercent = leftSideDistance / m_leftRightSideDistanceLength; } if (leftDistance > 0) { leftPercent = leftDistance / m_leftRightDistanceLength; } if (leftSidePercent < leftPercent) { result = localSteeringAngle * (1 - leftSidePercent); } else { result = localSteeringAngle * (1 - leftPercent); } } } else { result = localSteeringAngle; } } if (rightSideDistance != 0 && leftSideDistance != 0) { if (rightDistance > 0) { rightPercent = rightDistance / m_leftRightDistanceLength; } if (leftDistance > 0) { leftPercent = leftDistance / m_leftRightDistanceLength; } if (rightPercent < leftPercent || leftPercent == 0) { result = (-1) * localSteeringAngle * (1 - rightPercent); } else if (rightPercent > leftPercent || rightPercent == 0) { result = localSteeringAngle * (1 - leftPercent); } } break; case SteeringMode.Tough: //steering //steer left //Kein "(rightSideDistance > 0) ||" weil kein Abdrengeln möglich sein soll if (leftSideDistance == 0 && ((leftDistance == 0 && rightDistance > 0) || (rightDistance != 0 && leftDistance != 0 && leftDistance > rightDistance) || (leftDistance == 0 && frontMinDistance > 0) || (rightDistance > leftDistance && frontMinDistance > 0))) { if (!steerAbsolute) { if (frontMinDistance > 0) { result = (-1) * localSteeringAngle; //rightPercent = frontMinDistance / m_frontDistanceLength; //result = (-1) * localSteeringAngle * (1 - rightPercent); } else { if (rightDistance > 0) { rightPercent = rightDistance / m_leftRightDistanceLength; } result = (-1) * localSteeringAngle * (1 - rightPercent); } } else { result = (-1) * localSteeringAngle; } } //steer right //Kein "(leftSideDistance > 0) ||" weil kein Abdrengeln möglich sein soll if (rightSideDistance == 0 && ((rightDistance == 0 && leftDistance > 0) || (rightDistance != 0 && leftDistance != 0 && rightDistance > leftDistance) || (rightDistance == 0 && frontMinDistance > 0) || (leftDistance > rightDistance && frontMinDistance > 0))) { if (!steerAbsolute) { //result = localSteeringAngle; if (frontMinDistance > 0) { result = localSteeringAngle; //leftPercent = frontMinDistance / m_frontDistanceLength; //result = localSteeringAngle * (1 - leftPercent); } else { if (leftDistance > 0) { leftPercent = leftDistance / m_leftRightDistanceLength; } result = localSteeringAngle * (1 - leftPercent); } } else { result = localSteeringAngle; } } break; } return result; }
public RailedMoveBlock(Vector2 position, int width, int height, Vector2 node, SteeringMode steeringMode, float speed) : base(position, width, height, safe: false) { start = position; target = node; if (speed <= 0f) { steeringMode = SteeringMode.None; } else { moveSpeed = speed; } dir = Calc.SafeNormalize(target - start); length = Vector2.Distance(start, target); if (dir == Vector2.Zero) { steeringMode = SteeringMode.None; } else { if (dir.Y == 0 & (steeringMode == SteeringMode.Both || steeringMode == SteeringMode.Vertical)) { steeringMode = SteeringMode.Horizontal; } if (dir.X == 0 & (steeringMode == SteeringMode.Both || steeringMode == SteeringMode.Horizontal)) { steeringMode = SteeringMode.Vertical; } } this.steeringMode = steeringMode; hasSideButtons = steeringMode == SteeringMode.Both || steeringMode == SteeringMode.Horizontal; hasTopButtons = steeringMode == SteeringMode.Both || steeringMode == SteeringMode.Vertical; int tilesWidth = width / 8; int tilesHeight = height / 8; MTexture button = GFX.Game["objects/moveBlock/button"]; MTexture block; switch (steeringMode) { default: block = GFX.Game["objects/moveBlock/base"]; idleIcon = GFX.Game["objects/CommunalHelper/railedMoveBlock/o"]; break; case SteeringMode.Both: block = GFX.Game["objects/CommunalHelper/railedMoveBlock/base_both"]; idleIcon = GFX.Game["objects/CommunalHelper/railedMoveBlock/both"]; break; case SteeringMode.Vertical: block = GFX.Game["objects/moveBlock/base_h"]; idleIcon = GFX.Game["objects/CommunalHelper/railedMoveBlock/v"]; break; case SteeringMode.Horizontal: block = GFX.Game["objects/moveBlock/base_v"]; idleIcon = GFX.Game["objects/CommunalHelper/railedMoveBlock/h"]; break; } icon = idleIcon; if (hasTopButtons) { for (int i = 0; i < tilesWidth; i++) { int num3 = ((i != 0) ? ((i < tilesWidth - 1) ? 1 : 2) : 0); AddImage(button.GetSubtexture(num3 * 8, 0, 8, 8), new Vector2(i * 8, -4f), 0f, new Vector2(1f, 1f), topButton); } } if (hasSideButtons) { for (int j = 0; j < tilesHeight; j++) { int num4 = ((j != 0) ? ((j < tilesHeight - 1) ? 1 : 2) : 0); AddImage(button.GetSubtexture(num4 * 8, 0, 8, 8), new Vector2(-4f, j * 8), (float)Math.PI / 2f, new Vector2(1f, -1f), leftButton); AddImage(button.GetSubtexture(num4 * 8, 0, 8, 8), new Vector2((tilesWidth - 1) * 8 + 4, j * 8), (float)Math.PI / 2f, new Vector2(1f, 1f), rightButton); } } for (int i = 0; i < tilesWidth; i++) { for (int j = 0; j < tilesHeight; j++) { int tx = (i != 0) ? ((i < tilesWidth - 1) ? 1 : 2) : 0; int ty = (j != 0) ? ((j < tilesHeight - 1) ? 1 : 2) : 0; AddImage(block.GetSubtexture(tx * 8, ty * 8, 8, 8), new Vector2(i, j) * 8f, 0f, new Vector2(1f, 1f), body); } } UpdateColors(fillColor); Add(sfx = new SoundSource() { Position = new Vector2(width / 2f, Height / 2f) }); sfx.Play(CustomSFX.game_railedMoveBlock_railedmoveblock_move, "arrow_stop", 1f); Add(new LightOcclude(0.5f)); platformData = new DynData <Platform>(this); }