void SetCartPosition(float distanceAlongPath) { if (m_Path != null) { m_Distance = m_Path.StandardizeUnit(distanceAlongPath, CinemachinePathBase.PositionUnits.Distance); this.transform.position = m_Path.EvaluatePositionAtUnit(m_Distance, CinemachinePathBase.PositionUnits.Distance); //this.transform.rotation = m_Path.EvaluateOrientationAtUnit(m_Distance, CinemachinePathBase.PositionUnits.Distance); m_PathUnits = m_Path.FindClosestPoint(this.transform.position, 0, -1, 2); this.transform.rotation = m_Path.EvaluateOrientation(m_PathUnits, true); m_Speed_KPH = m_Path.EvaluateSpeed(m_PathUnits, out int indexA, out int indexB); m_Speed_MPS = ValueAdjust.ConvertSpeed(SpeedType.KPH, SpeedType.MPS, m_Speed_KPH); m_CurrentRoadWidth = m_Path.EvaluateWidth(m_PathUnits); m_CurrentYaw = m_Path.EvaluateYaw(m_PathUnits); Vector3 nextPos = m_Path.EvaluatePosition(m_Path.FindClosestPoint(this.transform.position + WheelForward.normalized * m_Speed_MPS, 0, 1, 2)); OutputSteerAngle = this.transform.DirectionToLocalEulerAngles(nextPos - this.transform.position).y; car.m_SteerAngle = OutputSteerAngle; UpdateWheels(OutputSteerAngle); } }
void SetCartPosition(Vector3 nowPosition, Vector3 direction, float speed, float step) { if (m_Path != null) { m_PathUnits = m_Path.FindClosestPoint(nowPosition + direction.normalized * speed * step, 0, -1, 2); m_Speed_KPH = m_Path.EvaluateSpeed(m_PathUnits, out int indexA, out int indexB); m_Speed_MPS = ValueAdjust.ConvertSpeed(SpeedType.KPH, SpeedType.MPS, m_Speed_KPH); Vector3 pos = m_Path.EvaluatePosition(m_PathUnits); m_CurrentRoadWidth = m_Path.EvaluateWidth(m_PathUnits); Vector3 right = ForwardToRight(m_Path.EvaluateTangent(m_PathUnits)); if (!ValueAdjust.InLine(this.transform.position, pos + right * m_CurrentRoadWidth, pos - right * m_CurrentRoadWidth, step)) { this.transform.position = pos; } this.transform.rotation = m_Path.EvaluateOrientation(m_PathUnits, true);// * Quaternion.Euler(Vector3.up * Random.Range(-1f, 1f)); m_CurrentYaw = m_Path.EvaluateYaw(m_PathUnits); Vector3 nextPos = m_Path.EvaluatePosition(m_Path.FindClosestPoint(this.transform.position + direction.normalized * speed, 0, 1, 2)); OutputSteerAngle = this.transform.DirectionToLocalEulerAngles(nextPos - this.transform.position).y; car.m_SteerAngle = OutputSteerAngle; UpdateWheels(OutputSteerAngle); } }
public float GetSpeed(SpeedType type) { return(ValueAdjust.ConvertSpeed(SpeedType.MPS, type, m_Rigidbody.velocity.magnitude)); }