void OnCollisionEnter(Collision col) { if (immobilized || spawnProtection < .5f) { return; } immobilized = true; signalsOn = SignalsOn.All; }
void OnReAligned() { immobilized = false; spawnProtection = 0f; rigid.velocity = Vector3.zero; rigid.angularVelocity = Vector3.zero; signalsOn = SignalsOn.Off; changingLines = ChangingLines.Straight; maximumSpeed = Random.Range(_maximumSpeed, _maximumSpeed * 1.5f); distance = 50f; }
void FixedUpdate() { if (!immobilized) { desiredSpeed = Mathf.Clamp(maximumSpeed - Mathf.Lerp(maximumSpeed, 0f, (distance - 10f) / 50f), 0f, maximumSpeed); } else { desiredSpeed = Mathf.Lerp(desiredSpeed, 0f, Time.fixedDeltaTime); } if (distance < 50) { brakingOn = true; } else { brakingOn = false; } if (!immobilized && HR_GamePlayHandler.mode != HR_GamePlayHandler.Mode.TwoWay) { transform.rotation = Quaternion.Lerp(transform.rotation, steeringAngle, Time.fixedDeltaTime * 3f); } rigid.velocity = Vector3.Slerp(rigid.velocity, transform.forward * desiredSpeed, Time.fixedDeltaTime * 3f); rigid.angularVelocity = Vector3.Slerp(rigid.angularVelocity, Vector3.zero, Time.fixedDeltaTime * 10f); if (!immobilized && HR_GamePlayHandler.mode != HR_GamePlayHandler.Mode.TwoWay) { switch (changingLines) { case ChangingLines.Straight: steeringAngle = Quaternion.identity; break; case ChangingLines.Left: if (currentLine == 0) { changingLines = ChangingLines.Straight; break; } if (transform.position.x <= HR_TrafficPooling.lines[currentLine - 1].position.x + .5f) { currentLine--; signalsOn = SignalsOn.Off; changingLines = ChangingLines.Straight; } else { steeringAngle = Quaternion.identity * Quaternion.Euler(0f, -5f, 0f); signalsOn = SignalsOn.Left; } break; case ChangingLines.Right: if (currentLine == (HR_TrafficPooling.lines.Length - 1)) { changingLines = ChangingLines.Straight; break; } if (transform.position.x >= HR_TrafficPooling.lines[currentLine + 1].position.x - .5f) { currentLine++; signalsOn = SignalsOn.Off; changingLines = ChangingLines.Straight; } else { steeringAngle = Quaternion.identity * Quaternion.Euler(0f, 5f, 0f); signalsOn = SignalsOn.Right; } break; } } }