// Update is called once per frame void Update() { if (!m_pathManager.M_DestinationReached()) { // Get next corner Vector3 nextCorner = m_pathManager.M_GetNextCorner(); Vector3 nextToCurrent = nextCorner - transform.position; // Start breaking if we're approaching the destination if (m_pathManager.M_GetDistanceToDestination() <= m_breakDistance) { Break(); } else { TurnWheels(nextToCurrent); Accelerate(); // Rotate car depending on wheel angle Vector3 pivotPoint = transform.position; // Should be rear wheels, I reckon m_unit.transform.RotateAround(pivotPoint, m_unit.transform.up, m_currentAngle * m_turnTime * Time.deltaTime); } // Move car Vector3 movement = transform.forward * m_currentMoveSpeed * Time.deltaTime; m_unit.transform.position += movement; } else // Hard stop { m_currentMoveSpeed = 0; } }
// Update is called once per frame void Update() { if (!m_pathManager.M_DestinationReached()) { // Get next corner Vector3 nextCorner = m_pathManager.M_GetNextCorner(); Vector3 nextToCurrent = nextCorner - transform.position; // Rotate so we're facing the target float angle = Helpers.GetDiffAngle2D(transform.forward, nextToCurrent); // If we're not looing at the target, turn the turret if (Mathf.Abs(angle) > 0) { float rotateAngle = Mathf.Sign(angle) * m_rotateSpeed * Time.deltaTime; // If we overshoot, set rotate to diff for perfect rotate if (Mathf.Abs(rotateAngle) > Mathf.Abs(angle)) { rotateAngle = angle; } m_unit.transform.Rotate(0, rotateAngle, 0, Space.World); // What happens if the tank tilts? Should be Space.World? } // If the rotation is enough, move forward if (Mathf.Abs(angle) < m_directionMargin) { m_unit.transform.position += transform.forward * m_moveSpeed * Time.deltaTime; } } }