[Edy's vehicle physics] а куда код написать переключение передач (файл...), куда вставлять место ?Добавлено (14 августа 2016, 23:25)
---------------------------------------------
куда вписать?
Код
...
void Update ()
{
if (spinUpdateRate == UpdateRate.Disabled)
{
foreach (WheelData wd in m_wheelData)
{
UpdateSteering(wd);
}
}
else
if (spinUpdateRate == UpdateRate.OnUpdate || wheelPositionMode == PositionMode.Accurate)
{
bool needDisableColliders = m_rigidbody.interpolation != RigidbodyInterpolation.None
&& wheelPositionMode == PositionMode.Accurate;
if (needDisableColliders)
DisableCollidersRaycast();
foreach (WheelData wd in m_wheelData)
{
UpdateSteering(wd);
UpdateTransform(wd);
}
if (needDisableColliders)
EnableCollidersRaycast();
}
// Drag state is smoothly faded to zero. It gets raised/modified from the drag contacts.
if (processContacts)
{
UpdateDragState(Vector3.zero, Vector3.zero, m_localDragHardness);
// debugText = string.Format("Drag Pos: {0} Drag Velocity: {1,5:0.00} Drag Friction: {2,4:0.00}", localDragPosition, localDragVelocity.magnitude, localDragFriction);
}
}
void FixedUpdate ()
{
// Ensure input values within range
throttleInput = Mathf.Clamp (throttleInput, -1.0f, +1.0f);
brakeInput = Mathf.Clamp01(brakeInput);
handbrakeInput = Mathf.Clamp01(handbrakeInput);
// Update common variables
m_speed = Vector3.Dot(m_rigidbody.velocity, m_transform.forward);
m_speedAngle = Vector3.Angle(m_rigidbody.velocity, m_transform.forward) * Mathf.Sign(m_speed);
// Prepare common data
float referenceDownforce =
computeExtendedTireData? (m_rigidbody.mass * Physics.gravity.magnitude) / m_wheelData.Length : 1.0f;
// Apply wheel physics
bool needUpdateVisuals =
spinUpdateRate == UpdateRate.OnFixedUpdate && wheelPositionMode == PositionMode.Fast;
int groundedWheels = 0;
foreach (WheelData wd in m_wheelData)
{
if (!disallowRuntimeChanges)
UpdateWheelCollider(wd.collider);
if (needUpdateVisuals)
UpdateSteering(wd);
UpdateSuspension(wd);
UpdateLocalFrame(wd);
UpdateGroundMaterial(wd);
ComputeTireForces(wd);
ApplyTireForces(wd);
UpdateWheelSleep(wd);
// Update visual wheel object
if (needUpdateVisuals)
UpdateTransform(wd);
if (wd.grounded) groundedWheels++;
// Calculate extended tire data
if (computeExtendedTireData)
ComputeExtendedTireData(wd, referenceDownforce);
}
// Apply aerodynamic properties
float sqrVelocity = m_rigidbody.velocity.sqrMagnitude;
Vector3 dragForce = -aeroDrag * sqrVelocity * m_rigidbody.velocity.normalized;
Vector3 loadForce = -aeroDownforce * sqrVelocity * m_transform.up;
Vector3 aeroAppPoint = m_transform.position + m_transform.forward * aeroAppPointOffset;
m_rigidbody.AddForceAtPosition(dragForce, aeroAppPoint);
if (groundedWheels > 0) m_rigidbody.AddForceAtPosition(loadForce, aeroAppPoint);
// debugText = string.Format("AeroDrag: {0,6:0.} AeroForce: {1,6:0.}", dragForce.magnitude, loadForce.magnitude);
// Handle impacts
if (processContacts)
HandleImpacts();
}
...
?