void LaneKeeping() { Transform furthest = CalculatePointDistance("Centerpoint"); if (furthest != null) { int index = furthest.GetSiblingIndex(); //this is the index of the furthest node within the circle, considering centerLine int lane = MonitorLane("Waypoint"); //this is to understand if I am partially in the oncoming lane Vector3 projectedPoint = linesUtils.CalculateProjectedPoint(transform.position, centerLine.transform.GetChild(index).position, centerLine.transform.GetChild(index - 1).position); float dist = Vector3.Distance(transform.position, projectedPoint); if (dist < 4.0f && lane == 0) { linesUtils.CenterLineColor = linesUtils.ChangeMatByDistance(dist); } else if (dist >= 4.0f && lane == 0) { linesUtils.CenterLineColor = new Color32(0xFF, 0xFF, 0xFF, 0xFF); } else if (lane != 0) { linesUtils.CenterLineColor = new Color32(0xFF, 0x00, 0x00, 0xFF); } linesUtils.DrawLineUrban(furthest, gameObject, projectedPoint, MonitorLane("Centerpoint")); //this is to understand the trip direction in order to draw the centerLine } cacheColls.Clear(); }
public void BoundingCubeLerperSF(CubesAndTags cubesAndTags, Bounds bounds, Sprite sprite, Vector3 trasl, int i) { Renderer cubeRend = cubesAndTags.boundingCube[i].GetComponent <Renderer>(); Canvas canvas = cubesAndTags.infoTag[i].GetComponent <Canvas>(); Vector3 targetPoint = new Vector3(cubesAndTags.other.transform.position.x, rayCastPos.transform.position.y, cubesAndTags.other.transform.position.z); Vector3 dirToTarget = (targetPoint - rayCastPos.transform.position); Animator animTag = cubesAndTags.infoTag[i].GetComponent <Animator>(); AudioSource audio = cubesAndTags.boundingCube[i].GetComponent <AudioSource>(); float dstToTarget = Vector3.Distance(rayCastPos.position, targetPoint); float viewAngle = 5f; if (dstToTarget <= 8f) { viewAngle = 25f; } if (Vector3.Angle(rayCastPos.TransformDirection(Vector3.forward), dirToTarget) < viewAngle / 2) { Debug.DrawLine(rayCastPos.position, targetPoint, Color.red); if (Physics.Raycast(rayCastPos.position, dirToTarget, dstToTarget, mask)) { float distToWarn = RiskAssessmentFormulaD(rigidbody.velocity.magnitude, 0, 0, dstToTarget, ResourceHandler.instance.visualisationVars.systemAccStaticSF); //velocity component of obstacles is null since they are orthogonal to the playerCar if (dstToTarget <= Mathf.Abs(distToWarn) && Mathf.Abs(vehicleController.steerInput) <= 0.001f) { float distToWarnEncoded = Mathf.Pow(distToWarn, 2.5f); float dstToTargetEncoded = Mathf.Pow(dstToTarget, 2.5f); bool blink = false; Color32 topColor = linesUtils.ChangeMatByDistance(dstToTargetEncoded / Mathf.Abs(distToWarnEncoded), ref blink, ref cubesAndTags); topColor.a = 0; Color32 bottomColor = linesUtils.ChangeMatByDistance(dstToTargetEncoded / Mathf.Abs(distToWarnEncoded), ref blink, ref cubesAndTags); bottomColor.a = 0x51; cubeRend.material.SetColor("_Color1", topColor); cubeRend.material.SetColor("_Color2", bottomColor); cubeRend.enabled = true; canvas.enabled = true; cubesAndTags.alreadyEvaluated = true; animTag.SetFloat("Multiplier", 3.0f); animTag.SetBool("BlinkLoop", blink); PlayAudio(audio, dstToTargetEncoded / Mathf.Abs(distToWarnEncoded), cubesAndTags); UpdateInfoTag(cubesAndTags, bounds, "0", sprite, dstToTarget, trasl, i); } else { cubeRend.enabled = false; canvas.enabled = false; animTag.SetBool("BlinkLoop", false); } } else { cubeRend.enabled = false; canvas.enabled = false; animTag.SetBool("BlinkLoop", false); } } else { cubeRend.enabled = false; canvas.enabled = false; animTag.SetBool("BlinkLoop", false); } } //this is for static objects. In order to show a smooth vanishing when exiting the gradient state I can do a fading animation and control it by a bool that is set in the gradient if and reset after the animation has been played