// Use this for initialization
    void Start()
    {
        move = GetComponent <Move>();
        seek = GetComponent <SteeringSeek>();

        // TODO 1: Calculate the closest point from the tank to the curve

        //float min_dist = float.MaxValue;
        //int closestPoint = 0;
        //for (int i = 0; i < curve.Curve.PointsCount; ++i)
        //{
        //    float newDist = Vector3.Distance(transform.position, curve.Curve[i].PositionWorld);
        //    if (newDist < min_dist)
        //    {
        //        min_dist = newDist;
        //        closestPoint = i;
        //    }
        //}
        //trgPoint = closestPoint;

        totalPathDist = path.GetDistance();//If you don't put anything you get the total distance of the path

        float distance = 0f;

        transform.position = path.CalcPositionByClosestPoint(transform.position, out distance);
        trgPointIdx        = path.CalcSectionIndexByDistance(distance);
        currRation         = trgPointRation = distance / totalPathDist;
    }
示例#2
0
    // Use this for initialization
    void Start()
    {
        NavMeshAgent agent = GetComponent <NavMeshAgent>();

        path.CalcPositionByClosestPoint(transform.position, out current_percentage);
        distance_ratio      = agent.speed / path.GetDistance();
        current_percentage /= path.GetDistance();
    }
示例#3
0
    // Use this for initialization
    void Start()
    {
        move = GetComponent <Move>();
        seek = GetComponent <SteeringSeek>();

        path.CalcPositionByClosestPoint(transform.position, out current_percentage);
        distance_ratio      = move.max_mov_velocity / path.GetDistance();
        current_percentage /= path.GetDistance();
    }
示例#4
0
    // Use this for initialization
    void Start()
    {
        move = GetComponent <Move>();
        seek = GetComponent <SteeringSeek>();

        // TODO 1: Calculate the closest point in the range [0,1] from this gameobject to the path
        path.CalcPositionByClosestPoint(transform.position, out current_percentage);
        distance_ratio      = move.max_mov_velocity / path.GetDistance();
        current_percentage /= path.GetDistance();
    }
示例#5
0
    // Use this for initialization
    void Start()
    {
        move  = GetComponent <Move>();
        seek  = GetComponent <SteeringArrive>();
        agent = GetComponent <PoliceBehaviour>();

        // TODO 1: Calculate the closest point in the range [0,1] from this gameobject to the path
        float startDistance;
        float distance = path.GetDistance();

        desiredPoint = path.CalcPositionByClosestPoint(transform.position, out startDistance);
        currentRatio = startDistance / distance;
    }
示例#6
0
    void Start()
    {
        distanceDone  = 0;
        distanceTotal = curveMath.GetDistance();

        currentPointIndex        = 0;
        pointToPointDistanceDone = 0;
        distanceToDo             = curveMath.GetDistance(currentPointIndex);
        pointIndexGoingUp        = true;
        currentIdleTween         = null;
        Replace();
        if (beginOnStart)
        {
            Begin();
        }
    }
示例#7
0
        public void AddNote(int i)
        {
            Debug.Log("Add Bird Note");
            int   count = notes.Count + 1;
            float dist  = math.GetDistance();

            int j = 0;

            foreach (GameObject note in notes)
            {
                float   distance = dist / count * j;
                Vector3 position = math.CalcPositionByDistance(distance);
                s.Append(note.transform.DOMove(new Vector3(position.x, position.y * Random.Range(0.8f, 1.2f)), 2f));
                j++;
            }


            float   newdist = dist / count * j;
            Vector3 newPos  = math.CalcPositionByDistance(newdist);

            newPos = new Vector3(newPos.x, newPos.y * Random.Range(0.8f, 1.2f), newPos.z);
            GameObject obj = Instantiate(notePrefabs[i], newPos, Quaternion.identity);

            obj.transform.localScale *= Mathf.Pow(1.1f, count);
            notes.Add(obj);
        }
示例#8
0
        // Remplis le GameObject avec des tiles suivant la BGCurve
        private void Populate()
        {
            _pathLength = _math.GetDistance();

            if (System.Math.Abs(TileSize) < 0.00001f)
            {
                Debug.LogError("TileSize must be != 0.0f");
            }

            int tilesCount = (int)Mathf.Floor(_pathLength / TileSize);

            if (tilesCount == 0)
            {
                // Pas de tile, sortie
                return;
            }

            // Compensation au niveau du scale des tiles
            _compensatedScale = _pathLength / tilesCount / TileSize;
            _compensatedSize  = TileSize * _compensatedScale;

            float tileOffset = 0.0f;

            for (int i = 0; i < tilesCount; i++)
            {
                AddTile(tileOffset);
                tileOffset += _compensatedSize;
            }

            // Premier placement des tiles
            _needsUpdate = true;
            UpdatePositions();
        }
示例#9
0
    // Start is called before the first frame update
    void Start()
    {
        float distance;

        closest_point = path.CalcPositionByClosestPoint(transform.position, out distance);

        current_ratio = distance / path.GetDistance();
    }
示例#10
0
 public void Init()
 {
     trackMath           = GetComponent <BGCcMath> ();
     LeftPoint           = trackMath.Curve.Points.First().PositionWorld;
     RightPoint          = trackMath.Curve.Points.Last().PositionWorld;
     LeftTrackPathUnits  = new List <TrackPathUnit> ();
     RightTrackPathUnits = new List <TrackPathUnit> ();
     PathLenght          = trackMath.GetDistance();
 }
示例#11
0
    void Start()
    {
        cam = currentCameraGO.Value.GetComponent <Camera>();

        curveMath     = curve.GetComponent <BGCcMath>();
        distanceDone  = 0;
        distanceTotal = curveMath.GetDistance();
        Compute();
    }
示例#12
0
    // Use this for initialization
    void Start()
    {
        move = GetComponent <Move>();
        seek = GetComponent <SteeringSeek>();
        //    path = GetComponent<FollowCurve>().path;

        // TODO 1: Calculate the closest point from the tank to the curve
        current_point  = path.CalcPositionByClosestPoint(transform.position, out current_ratio);
        current_ratio /= path.GetDistance();
    }
示例#13
0
    // Use this for initialization
    void Start()
    {
        move = GetComponent <Move>();
        seek = GetComponent <SteeringSeek>();

        // TODO 2: Calculate the closest point in the range [0,1] from this gameobject to the path
        closest_point = path.CalcPositionByClosestPoint(transform.position, out point_distance);
        tot_distance  = path.GetDistance();
        current_pos   = point_distance / tot_distance;
    }
示例#14
0
    // Use this for initialization
    void Start()
    {
        move = GetComponent <Move>();
        seek = GetComponent <SteeringSeek>();

        // TODO 1: Calculate the closest point from the tank to the curve
        float distance;

        closest_point = path.CalcPositionByClosestPoint(move.transform.position, out distance);
        current_ratio = distance / path.GetDistance();
    }
示例#15
0
    // Use this for initialization
    void Start()
    {
        move = GetComponent <Move>();
        seek = GetComponent <SteeringSeek>();

        // TODO 1: Calculate the closest point in the range [0,1] from this gameobject to the path
        float distance;

        closet_point = path.CalcPositionByClosestPoint(transform.position, out distance);

        range_distance = distance / path.GetDistance();
    }
示例#16
0
    void Start()
    {
        rightView = true;

        math      = Curve.GetComponent <BGCcMath>();
        headPoint = Curve.Points[0];
        midPoint  = Curve.Points[1];
        tailPoint = Curve.Points[2];

        Length      = math.GetDistance();
        minDistance = Length * 0.5f;
        prevLength  = Length;

        //UpdateBones();
    }
示例#17
0
    private void Start()
    {
        math = Route.GetComponent <BGCcMath>();

        // Длина маршрута
        totalDistance = math.GetDistance();
        // Debug.Log("totalDistance = " + totalDistance);

        // добавляем +1 , чтобы не было в краях дистанции
        // Пример: дистанция 10, нужно 4 предметов, но не нужно в 0 и в 10;
        // получится как раз в координатах 2 4 6 8
        spawnDistance = totalDistance / (SpawnCount + 1);
        // Debug.Log("spawnDistance = " + spawnDistance);

        Spawn();
    }
示例#18
0
 // Reset the bird
 private void resetBird()
 {
     // Reset player group position
     flightPathCursors[0].Distance = 0;
     // Reset bird local position and velocity
     playerController.gameObject.transform.localPosition             = new Vector3(0, 0, 0);
     playerController.gameObject.GetComponent <Rigidbody>().velocity = new Vector3(0, 0, 0);
     // Reset camera position
     flightPathCursors[1].Distance = flightPathMath.GetDistance() - cameraDistance;
     // Reset its animation
     playerAnim.SetDeathAnimation(false);
     // Dsiable user animation
     playerAnim.SetUserAnimation(false);
     // Turn oon Z-axis constraint
     playerController.SetConstrainZ(true);
     // Disable physics
     enablePhysics(false);
 }
示例#19
0
        // Update is called once per frame
        void Update()
        {
            if (!finished && touchPosition != null)
            {
                Vector3 point = touchPosition;
                point.z = 4.9f;

                float   newDistance;
                Vector3 pointOnCurve = curve.GetComponent <BGCcMath>().CalcPositionByClosestPoint(point, out newDistance);
                if (newDistance - distance < 1 && newDistance - distance > 0)
                {
                    distance = FillIntoLine(pointOnCurve, distance, newDistance);
                    particle.transform.position = pointOnCurve;
                    startdrawing = true;
                }
                else if (newDistance == math.GetDistance() && newDistance - distance < 1 && startdrawing)
                {
                    finished = true;
                    particle.gameObject.SetActive(false);
                    StretchLine();
                    game.Proceed();
                }
            }
        }
示例#20
0
    public bool CanMove(float displacement)
    {
        float newDistance = Mathf.Clamp(distance + displacement, 0, curve.GetDistance());

        return(newDistance < curve.GetDistance() && newDistance > 0);
    }
    /// <summary>
    /// Update the player's velocity and direction of movement based on the current state
    /// </summary>
    /// <param name="input"></param>
    public void Move(float input)
    {
        if (!m_touchingGround && !m_droppingIn)
        {
            m_currentSpeed = Mathf.Lerp(m_currentSpeed, m_rb.velocity.magnitude, 0.05f);
        }
        if (m_touchingGround && m_rb.velocity.magnitude > m_currentSpeed)
        {
            m_currentSpeed = m_rb.velocity.magnitude;
        }

        //in vert
        if (m_vert)
        {
            Vector3 m_currentRampPos;
            // Find the position on the coping spline that is closest to the player
            m_currentRampPos = m_currentQuaterPipe.CalcPositionByClosestPoint(transform.position, out float dist, out Vector3 tangent);

            // Calculate the player's new up based on the tangent of the current position on the spline
            Vector3 norm        = Vector3.Cross(tangent, Vector3.up).normalized;
            float   signedAngle = Vector3.SignedAngle(norm, m_currentUp, Vector3.up);
            m_targetRotation -= signedAngle;
            m_currentUp       = norm;

            // Correct the position's y value based on the player's y position
            m_currentRampPos.y = transform.position.y;

            // If the player is still within the bounds of the ramp's coping spline
            if (dist > 0 && dist < m_currentQuaterPipe.GetDistance())
            {
                m_rb.MovePosition(Vector3.Lerp(m_rb.position, m_currentRampPos, 0.5f));
            }

            // Grab a reference to the player's velocity
            Vector3 velocity = m_rb.velocity;
            // remove the vertical component for now
            velocity.y = 0;
            // Find the direction on the spline that the player is moving (tangent)
            Vector3 tan = (Vector3.Dot(velocity.normalized, tangent) > 0) ? tangent : -tangent;
            // Take out the vertical component
            tan.y = 0;
            tan.Normalize();
            // Force the velocity to coincide with the tangent
            velocity = tan * velocity.magnitude;
            // Re-introduce the vertical component of the velocity
            velocity.y    = m_rb.velocity.y;
            m_rb.velocity = velocity;
            return;
        }

        //grinding
        if (m_grinding)
        {
            Vector3 m_currentRailPos;
            // Find the position on the coping spline that is closest to the player
            m_currentRailPos = m_currentRail.CalcPositionByClosestPoint(transform.position, out float dist, out Vector3 tangent);

            // Calculate the player's new up based on the tangent of the current position on the spline
            Vector3 tanOfTangent = Vector3.Cross(tangent, Vector3.up).normalized;
            m_currentUp = -Vector3.Cross(tangent, tanOfTangent).normalized;

            // If the player is still within the bounds of the rail's spline
            if (dist > 0 && dist < m_currentRail.GetDistance())
            {
                m_rb.MovePosition(Vector3.Lerp(m_rb.position, m_currentRailPos, 0.5f));
            }

            // Grab a reference to the player's velocity
            Vector3 velocity = m_rb.velocity;
            // Find the direction on the spline that the player is moving (tangent)
            Vector3 tan = (Vector3.Dot(velocity.normalized, tangent) > 0) ? tangent : -tangent;
            // Force the velocity to coincide with the tangent
            velocity         = tan * m_currentSpeed;
            m_rb.velocity    = velocity;
            m_touchingGround = true;

            // Rotate to face the correct direction
            float signedAngle = Vector3.SignedAngle(m_moveDir, tan, m_currentUp);
            m_targetRotation += signedAngle / 2;
            m_currentRotation = m_targetRotation;

            Quaternion rotation = Quaternion.Euler(0, m_currentRotation, 0);
            // Find the tilt around based on the player's relative up
            Quaternion tilt = Quaternion.FromToRotation(Vector3.up, m_currentUp);
            // Apply the rotation combined with the tilt to the player's rotation
            transform.rotation = tilt * rotation;

            return;
        }

        //grounded
        if (m_touchingGround)
        {
            //holding faster
            if (input > 0)
            {
                if (m_currentSpeed < m_cruisingSpeed * 2)
                {
                    m_currentSpeed = Mathf.Lerp(m_currentSpeed, m_cruisingSpeed * 2, 0.01f);
                }
            }
            //holding nothing
            if (input == 0)
            {
                if (m_currentSpeed < m_cruisingSpeed)
                {
                    m_currentSpeed = Mathf.Lerp(m_currentSpeed, m_cruisingSpeed, 0.01f);
                }
                else
                {
                    m_currentSpeed -= 0.1f;
                }
            }
            //holding slower
            if (input < 0)
            {
                m_currentSpeed = Mathf.Lerp(m_currentSpeed, 0, 0.1f);
            }

            // Set the player's velocity
            m_rb.velocity = m_currentSpeed * m_moveDir;

            // Move the player to the ground
            m_rb.MovePosition(Vector3.Lerp(m_rb.position, m_currentGroundPos, 0.05f));
        }
    }