Example #1
0
    private void Update()
    {
        if (_ballRigidbody == null || _trajectoryRenderer == null)
        {
            return;
        }

        _speed = _ballRigidbody.velocity.magnitude;

        var goLO = _ballRigidbody.gameObject.GetComponent <LaunchableObject>();

        if (goLO != null && goLO.IsLaunched)
        {
            if (_speed < _speedStopThreshold)
            {
                _ballRigidbody.velocity = new Vector3(0, 0, 0);

                _trajectoryRenderer.positionCount = _points.Count;

                _trajectoryRenderer.SetPositions(_points.ToArray()); // See: https://answers.unity.com/questions/1226025/how-to-render-a-linerenderer-through-multiple-poin.html

                goLO.TotalPosition = _ballRigidbody.gameObject.transform.position;

                goLO.IsLaunched = false;

                _isTrajectoryDrawn = true;

                TrajectoryDataContent tdc = Camera.main.GetComponentInChildren <TrajectoryDataContent>();

                var decimalDigits = tdc.DecimalDigits >= 0 ? tdc.DecimalDigits : 0;
                tdc.OnLaunchEvent(_ballRigidbody.gameObject.transform.name + " Total: " + Vector3.Distance(goLO.TotalPosition, goLO.StartPosition).ToString("n" + decimalDigits));

                OnPostLaunch();

                return;
            }
        }

        if (!_isTrajectoryDrawn)
        {
            if (Mathf.Abs(Time.time - _countTime) >= _timePointSamplingThreshold)
            {
                _points.Add(_ballRigidbody.gameObject.transform.position);

                _countTime = Time.time;
            }
        }
    }
    public void ReceiveCollision(Collision c)
    {
        if (_ballRigidbody == null)
        {
            return;
        }

        if (_numOfCollisions == 0)
        {
            CarryPosition = _ballRigidbody.gameObject.transform.position;

            TrajectoryDataContent tdc = Camera.main.GetComponent <TrajectoryDataContent>();

            tdc.OnLaunchEvent(gameObject.transform.name + " Carry: " + Vector3.Distance(CarryPosition, StartPosition).ToString());
        }

        _numOfCollisions++;
    }
    private void Update()
    {
        if (_ballRigidbody == null || _trajectoryRenderer == null)
        {
            return;
        }

        _speed = _ballRigidbody.velocity.magnitude;

        if (_isLaunched)
        {
            if (_speed < 0.1)
            {
                _ballRigidbody.velocity = new Vector3(0, 0, 0);

                _trajectoryRenderer.positionCount = _points.Count;

                _trajectoryRenderer.SetPositions(_points.ToArray());

                TotalPosition = _ballRigidbody.gameObject.transform.position;

                _isLaunched = false;

                _isTrajectoryDrawn = true;

                TrajectoryDataContent tdc = Camera.main.GetComponentInChildren <TrajectoryDataContent>();

                tdc.OnLaunchEvent(gameObject.transform.name + " Total: " + Vector3.Distance(TotalPosition, StartPosition).ToString());

                return;
            }
        }

        if (!_isTrajectoryDrawn)
        {
            if (Mathf.Abs(Time.time - _countTime) >= 0.05f)
            {
                _points.Add(_ballRigidbody.gameObject.transform.position);

                _countTime = Time.time;
            }
        }
    }
Example #4
0
    public void ReceiveCollision(Collision c)
    {
        var goLO = c.gameObject.GetComponent <LaunchableObject>();

        if (goLO == null || !goLO.IsLaunched)
        {
            return;
        }

        if (_numOfCollisions == 0)
        {
            goLO.CarryPosition = c.rigidbody.gameObject.transform.position;

            TrajectoryDataContent tdc = Camera.main.GetComponentInChildren <TrajectoryDataContent>();

            var decimalDigits = tdc.DecimalDigits >= 0 ? tdc.DecimalDigits : 0;
            tdc.OnLaunchEvent(c.rigidbody.gameObject.transform.name + " Carry: " + Vector3.Distance(goLO.CarryPosition, goLO.StartPosition).ToString("n" + decimalDigits));
        }

        _numOfCollisions++;
    }