Exemplo n.º 1
0
        private void BuildLines(float totalTime, Vector3 gravity)
        {
            if (totalTime <= 0)
            {
                lineRenderer.positionCount = 0;
                return;
            }

            var dt = 0.05f;

            len = (int)(totalTime / dt) + 1;
            if (len > positions.Length)
            {
                len = positions.Length;
            }

            var startSpeed    = transform.forward.normalized * initialSpeed;
            var startPosition = transform.position;

            for (var i = 0; i < len; i++)
            {
                var t     = (totalTime * i) / (len - 1);
                var point = ParabolaHelpers.GetArcPositionAtTime(t, startSpeed, startPosition, gravity);
                positions[i] = transform.worldToLocalMatrix.MultiplyPoint(point);
            }

            lineRenderer.positionCount = len;
            lineRenderer.SetPositions(positions);
        }
Exemplo n.º 2
0
        public override bool GetRay(out Ray finalRay, Func <Vector3, Vector3, RaycastResult> raycast)
        {
            var g             = Physics.gravity;
            var startSpeed    = transform.forward.normalized * initialSpeed;
            var startPosition = transform.position;
            var result        = ParabolaHelpers.FindRay(g, startPosition, startSpeed, dist, raycast, out LastRay, out time);

            finalRay = LastRay;
            BuildLines(time, g);
            return(result);
        }