Example #1
0
    private IEnumerator Movement(Transform firstItem, Transform secondItem, SwitchDelegate onSwitched = null)
    {
        var pos1  = firstItem.position;
        var pos2  = secondItem.position;
        var speed = 5f * Time.deltaTime;
        var delay = new WaitForSeconds(0.3f);

        onSwitched = _onSwitched;

        while (true)
        {
            secondItem.position = Vector3.MoveTowards(secondItem.position, pos1, speed);
            firstItem.position  = Vector3.MoveTowards(firstItem.position, pos2, speed);

            // at the end of movement
            if (Vector3.Distance(firstItem.position, pos2) < 0.1f)
            {
                firstItem.position  = pos2;
                secondItem.position = pos1;
                yield return(delay);

                onSwitched?.Invoke();
                Debug.Log("valid");
                yield break;
            }

            yield return(null);
        }
    }
Example #2
0
    private IEnumerator TranslateMealToMouth()
    {
        if (!isCollectible)
        {
            yield break;
        }
        _collider2D.enabled = false;
        _rb.bodyType        = RigidbodyType2D.Static;

        while (Vector3.Distance(transform.position, _catMouth.position) > 0.3f)
        {
            transform.position = Vector3.MoveTowards(transform.position, _catMouth.position, _step);
            if (transform.lossyScale.x > 0.8f)
            {
                var mealTransform = transform;
                var scale         = mealTransform.localScale.x;
                scale -= 0.01f;
                mealTransform.localScale = new Vector3(scale, scale, scale);
            }
            yield return(Yielders.FixedUpdate);
        }
        if (!isFreezeEvent)
        {
            OnCollect?.Invoke(gameObject);
            isCollectedEvent.Invoke();
            DestroyObject();
        }
        else
        {
            Reject();
        }
    }
Example #3
0
        public override void UpdateCharacter()
        {
            base.UpdateCharacter(); // Call parent update

            inertia = Inertia;

            ManageInput();

            ManageWaves();

            var     pos = new Vector2(transform.position.x, transform.position.z);
            Vector3 normal;
            var     y      = water.getHeightAtPoint(pos, out normal);
            var     newPos = new Vector3(pos.x, y, pos.y);

            transform.position = Vector3.MoveTowards(transform.position, newPos, Time.deltaTime);

            water.Offset = new Vector3(PlayerOffset.x, 0f, PlayerOffset.y);
            //water.DirectionSpeed = new Vector2(Speed, Speed);
            Vector3 dir = GetDirection();
            //water.Direction = new Vector2(dir.x, dir.z);

            var direction = GetDirection();

            water.Direction      = new Vector2(direction.x, direction.z);
            water.DirectionSpeed = new Vector2(Speed * Time.deltaTime, Speed * Time.deltaTime);

            PlayerOffset += water.Direction * water.DirectionSpeed * Time.deltaTime * 0.25f;
        }
 private void Update()
 {
     if (Vector3.MoveTowards(transform.position, getTarget(), movmentSpeed) == Vector3.zero)
     {
         currentPoint = (currentPoint + 1) % 2;
     }
 }
Example #5
0
    public IEnumerator MovePlayer(Vector3 targetPosition)
    {
        isMoving = true;

        while ((targetPosition - transform.position).sqrMagnitude > Mathf.Epsilon)
        {
            if (hasTeleported)
            {
                break;
            }
            transform.position = Vector3.MoveTowards(transform.position, targetPosition, moveSpeed * Time.deltaTime);
            //          Debug.Log("In loop " + i);
            yield return(null);
        }
//        i++;
//        Debug.Log("Outside loop");

        if (!hasTeleported)
        {
            transform.position = targetPosition;
        }
        hasTeleported = false;
        isMoving      = false;
        checkForEncounter();
    }
Example #6
0
 void CheckForRaiseFlag()
 {
     if(GetDistanceFromBall() < raiseRadius)
     {
         DecideRaiseHeight();
         Vector3.MoveTowards(transform.position, new Vector3(transform.position.x, currentHeight, transform.position.z), 20f * Time.deltaTime);
         lastDistance = GetDistanceFromBall();
     }
 }
Example #7
0
    private void UpdatePositions()
    {
        var step       = moveSpeed * Time.deltaTime;
        var collBounds = coll.bounds;

        chaseGoalPos = player.transform.position + new Vector3(0, collBounds.extents.y, 0);
        policeCarPos = policeCar.transform.position;
        endGoalPos   = chaseGoalPos + new Vector3(0, 0, -collBounds.size.z * 1.5f);

        //move to current goal
        policeCar.transform.position = Vector3.MoveTowards(policeCarPos, currentGoal, step);
    }
Example #8
0
    private void FixedUpdate()
    {
        if (target != null)
        {
            float fixedSpeed = speed * Time.deltaTime;
            transform.position = Vector3.MoveTowards(transform.position, target.position, fixedSpeed);
        }

        if (transform.position == target.position)
        {
            target.position = (target.position == startPos) ? endPos : startPos;
        }
    }
        private void Update()
        {
            Vector3 toTarget           = TargetPoint - transform.position;
            float   distanceFromTarget = toTarget.magnitude;

            if (distanceFromTarget < distanceTolerance)
            {
                CurrentSpeed       = 0.0f;
                transform.position = TargetPoint;
                return;
            }

            Quaternion targetRotation = Quaternion.LookRotation(toTarget.normalized);
            float      angleRemaining = Quaternion.Angle(transform.rotation, targetRotation);

            if (angleRemaining > rotationTolerance)
            {
                if (CurrentRotationSpeed < maxRotationSpeedInDegrees)
                {
                    CurrentRotationSpeed += rotationAccelerationInDegrees * Time.deltaTime;
                }
                Mathf.Min(CurrentRotationSpeed, maxRotationSpeedInDegrees);

                transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation,
                                                              CurrentRotationSpeed * Time.deltaTime);
                return;
            }

            if (distanceFromTarget <= decelerationDistance)
            {
                if (!isDecelerating)
                {
                    isDecelerating = true;
                    deceleration   = 0.5f * CurrentSpeed * CurrentSpeed / decelerationDistance;
                }

                CurrentSpeed -= deceleration * Time.deltaTime;
                if (CurrentSpeed < speedTolerance)
                {
                    CurrentSpeed       = 0;
                    transform.position = TargetPoint;
                }
            }
            else if (CurrentSpeed < maxSpeed)
            {
                CurrentSpeed += acceleration * Time.deltaTime;
            }
            CurrentSpeed = Mathf.Min(CurrentSpeed, maxSpeed);

            transform.position = Vector3.MoveTowards(transform.position, TargetPoint, CurrentSpeed * Time.deltaTime);
        }
Example #10
0
    public IEnumerator GoToJailCoroutine() //send to jail, RIGHT THROUGH BOARD, DO NOT PASS OTHER TILES
    {
        Vector3 finalPosition = TileManager.GetTile(10).GetTilePosition();

        while (currentPosition != finalPosition)
        {
            currentPosition = Vector3.MoveTowards(currentPosition, finalPosition, 20f);
            {
                UpdatePosition();
                yield return(null);
            }
        }
        currentWaypoint = 10;
        inJail          = true;
        PlayerInformationManager.UpdatePlayerInfo();
        GameLoop.EndTurn();
    }
Example #11
0
 IEnumerator MovePlayerCoroutine()
 {
     isMoving = true;
     for (int i = 0; i < positions.Length; i++)
     {
         Vector3 nextPos = positions[i];
         while (Vector3.Distance(transform.position, nextPos) > .0001)
         {
             transform.position = Vector3.MoveTowards(transform.position, nextPos, speed * Time.deltaTime);
             if (i == positions.Length - 1)
             {
                 isMoving = false;
             }
             yield return(null);
         }
     }
 }
Example #12
0
    //Only clients
    private void Update()
    {
        if (PhotonNetwork.IsMasterClient)
        {
            return;
        }

        //Debug.Log(worldPieces_destiny[0]);
        for (var index = 0; index < worldPieces.Count; index++)
        {
            var piece = worldPieces[index];
            piece.transform.position =
                Vector3.MoveTowards(
                    piece.transform.position,
                    Vector3.up * worldPieces_destiny[index],
                    pieceFallMaxStep);
        }
    }
Example #13
0
    // Update is called once per frame
    void Update()
    {
        if (!m_hasTarget)
        {
            m_hasTarget = CanFindTarget();
        }
        else
        {
            RotateNPC(m_wayPoint, m_speed);
            transform.position = Vector3.MoveTowards(transform.position, m_wayPoint, m_speed * Time.deltaTime);
            CollidedNPC();
        }

        if (transform.position == m_wayPoint)
        {
            m_hasTarget = false;
        }
    }
Example #14
0
    void Move()
    {
        if (isTouched)
        {
            Vector3 distancePos = (mainCam.ScreenToViewportPoint(Input.mousePosition) * 5 - startPos);
            var     temp        = distancePos.y;
            distancePos.y  = 0;
            distancePos.z  = temp * 4;
            distancePos.x *= 2;

            targetPosition = playerPos + distancePos;
            CheckBounds();

            var delta = 6 * Time.deltaTime;
            delta *= Vector3.Distance(transform.localPosition, targetPosition);
            Vector3 movePos = Vector3.MoveTowards(transform.localPosition, targetPosition, delta);
            rb.MovePosition(movePos);
        }
    }
    private void FixedUpdate()
    {
        //  rb.velocity = Vector3.zero;
        //  rb.MovePosition(Vector3.MoveTowards(rb.position, getTarget(), movmentSpeed));
        transform.position = Vector3.MoveTowards(transform.position, transform.forward * 1000, movmentSpeed);

        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, 5000))
        {
            if (hit.transform.gameObject.CompareTag("wall"))
            {
                if (hit.distance < 0.8f)
                {
                    transform.Rotate(new Vector3(0, 180, 0));
                }
            }
        }
    }
Example #16
0
    // Traditional move sequence
    public virtual void Move()
    {
        // Get current target position
        Vector3 playerPos = player.transform.position;

        // Get adjusted target position of where the enemy wants to go
        playerPos.x += xDir; playerPos.z += zDir;

        // Draw the approprate vectors and move towards that position slowly
        Vector3 pos  = Vector3.MoveTowards(transform.position, playerPos, movementSpeed * Time.deltaTime * _speedMultiplier);
        Vector3 diff = Absolute(transform.position) - Absolute(pos);

        // Get adjusted height; THIS NEEDS WORK
        diff.y             = Terrain.activeTerrain.SampleHeight(transform.position) + Terrain.activeTerrain.GetPosition().y + 0.05f;
        transform.position = pos;

        // Look at target player
        transform.LookAt(player.transform);
    }
    private void MovePlayer()
    {
        if (_player.transform.position.x != targetPosition.x)
        {
            _animator.SetBool("isWalk", true);

            _player.transform.position =
                Vector3.MoveTowards(_player.transform.position,
                                    targetPosition,
                                    _speed * Time.deltaTime);
            Moving?.Invoke(true);
        }
        else
        {
            _animator.SetBool("isWalk", false);

            ChangeDirection(180);
            Moving?.Invoke(false);
        }
    }
Example #18
0
        private void FixedUpdate()
        {
            //move
            RaycastHit hit;

            if (Physics.Linecast(this.transform.position, child.transform.position, out hit))
            {
                if (hit.distance <= 1)
                {
                    //you are close enough to comfort, do so
                    doneCallback(this);
                }
                else
                {
                    //movement
                    float step = speed * Time.deltaTime;
                    transform.position = Vector3.MoveTowards(transform.position, child.transform.position, step);
                }
            }
        }
Example #19
0
    private void RotateViaDir(Vector3 targPos)
    {
        float rotSpeed = Owner.StateMachineOwner.ThisStats.GetRotationSpeed;
        float rotSpeedWithTimeDelta = rotSpeed * Time.deltaTime;

        Vector3 turretDir = targPos - turretPivot.position;
        Vector3 cannonDir = targPos - cannonPivot.position;

        Vector3 newTurretForward = new Vector3(turretDir.x, 0f, turretDir.z);
        Vector3 newCannonRight   = new Vector3(cannonDir.x, cannonDir.y, cannonDir.z);

        Vector3 turretSmoothing = Vector3.MoveTowards(turretPivot.right, newTurretForward, rotSpeedWithTimeDelta * 2f);

        // DrawDebugRays(targPos);

        turretPivot.right = turretSmoothing;

        Vector3 cannonSmoothing = Vector3.MoveTowards(cannonPivot.right, newCannonRight, rotSpeedWithTimeDelta * 0.5f);

        cannonPivot.right = cannonSmoothing;
    }
Example #20
0
    public virtual void Movement()
    {
        if (transform.position == pointA.position)
        {
            _currentTarget = pointB.position;
            _anim.SetTrigger("Idle");
            _spriteRend.flipX = false;
        }
        else if (transform.position == pointB.position)
        {
            _currentTarget = pointA.position;
            _anim.SetTrigger("Idle");
            _spriteRend.flipX = true;
        }

        if (_isHit == false)
        {
            transform.position = Vector3.MoveTowards(transform.position, _currentTarget, speed * Time.deltaTime);
        }

        float distance = Vector3.Distance(transform.localPosition, player.transform.localPosition);

        if (distance > 2.0f)
        {
            _isHit = false;
            _anim.SetBool("InCombat", false);
        }

        Vector3 direction = player.transform.localPosition - transform.localPosition;

        if (direction.x < 0 && _anim.GetBool("InCombat") == true)
        {
            _spriteRend.flipX = true;
        }
        else if (direction.x > 0 && _anim.GetBool("InCombat") == true)
        {
            _spriteRend.flipX = false;
        }
    }
Example #21
0
    public IEnumerator SendCoroutine(int location) //send to a specific location
    {
        Vector3 finalPosition = TileManager.GetTile(location).GetTilePosition();

        while (currentPosition != finalPosition)
        {
            Vector3 nextPosition = TileManager.GetTile(GetNextMovementWaypoint(1)).GetTilePosition();

            while (currentPosition != nextPosition)
            {
                currentPosition = Vector3.MoveTowards(currentPosition, nextPosition, 30f);
                UpdatePosition();
                yield return(null);
            }
            currentWaypoint = GetNextMovementWaypoint(1);
            if (currentWaypoint == 0)
            {
                Pay(200);
            }
        }
        TileManager.GetTile(currentWaypoint).DoTileAction();
    }
Example #22
0
    public IEnumerator MoveCoroutine(int diceSum)
    {
        Vector3 finalPosition = TileManager.GetTile(GetNextMovementWaypoint(diceSum)).GetTilePosition();

        while (currentPosition != finalPosition)
        {
            Vector3 nextPosition = TileManager.GetTile(GetNextMovementWaypoint(1)).GetTilePosition();

            while (currentPosition != nextPosition)
            {
                currentPosition = Vector3.MoveTowards(currentPosition, nextPosition, 10f);
                UpdatePosition();
                yield return(null);
            }
            currentWaypoint = GetNextMovementWaypoint(1);
            if (currentWaypoint == 0)
            {
                Pay(200);
            }
        }
        TileManager.GetTile(currentWaypoint).DoTileAction();
    }
Example #23
0
        public void Run()
        {
            foreach (var index in _filter)
            {
                ref var component = ref _filter.Get1(index);

                if (component.TargetDirection == Vector3.zero)
                {
                    continue;
                }

                var position         = component.Object.transform.position;
                var targetPosition   = component.TargetDirection;
                var releasedPosition = Vector3.MoveTowards(position, component.TargetDirection, Time.deltaTime);

                if (releasedPosition == targetPosition)
                {
                    component.TargetDirection = Vector3.zero;
                    continue;
                }

                component.Object.transform.position = releasedPosition;
            }
    void Update()
    {
        if (vieScriptG.vieValue == 0)
        {
            transition.timeAffichage = 250;
            SceneManager.LoadScene("joueurGagnant", LoadSceneMode.Single);
        }
        if (timeRemainingVieG > 0)
        {
            timeRemainingVieG -= 1;
        }
        else if (timeRemainingVieG < 0)
        {
            timeRemainingVieG = 0;
        }
        ///////////////////////////////////
        if (timeRemainingAccelerationG > 0)
        {
            timeRemainingAccelerationG -= 1;
        }
        else
        {
            if (timeACG > 0)
            {
                mouvementRoueD.boostVitesse = -0.01f;
                timeACG -= 1;
            }
            else if (timeACG == 0 && timeRLG == 0)
            {
                mouvementRoueD.boostVitesse = 0.0f;
            }
        }
        /////////////////////////////////////

        if (timeRemainingRalentiG > 0)
        {
            timeRemainingRalentiG -= 1;
        }
        else
        {
            if (timeRLG > 0)

            {
                mouvementRoueD.boostVitesse = 0.01f;
                timeRLG -= 1;
            }
            else if (timeACG == 0 && timeRLG == 0)
            {
                mouvementRoueD.boostVitesse = 0.0f;
            }
        }

        // Augmente la vitesse de rotation de la roue
        // au fur et à meusure que le temps passefd

        float step = speed * Time.deltaTime / menuDemarrage.attribuSpeed + boostVitesse;         // calculate distance to move

        // Champ du viseur dans lequel le joueur peut interagire avec la note
        if (Input.GetKeyDown("k") && this.gameObject.GetComponent <SpriteRenderer>().sprite == notePrehistoire)
        {
            if (!(triggerP1G.verifTrigger1G &&
                  triggerP4G.verifTrigger4G &&
                  triggerP3G.verifTrigger3G &&
                  triggerP2G.verifTrigger2G))
            {
                if (timeRemainingVieG == 0)
                {
                    timeRemainingVieG   += 2500;
                    vieScriptG.vieValue -= 1;
                    combo = 1;
                }
            }
            else if (this.transform.position.x >= 2.5f &&               //2
                     this.transform.position.x <= 3.4f &&               //4
                     this.transform.position.y >= -0.5f &&              //3
                     this.transform.position.y <= 0.5f)
            {
                apparitionPrehistoire();
            }
        }
        if (Input.GetKeyDown("k") && this.gameObject.GetComponent <SpriteRenderer>().sprite == noteFuture)
        {
            if (!(triggerP1G.verifTrigger1G &&
                  triggerP4G.verifTrigger4G &&
                  triggerP3G.verifTrigger3G &&
                  triggerP2G.verifTrigger2G))
            {
                if (timeRemainingVieG == 0)
                {
                    timeRemainingVieG   += 2500;
                    vieScriptG.vieValue -= 1;
                    combo = 1;
                }
            }
            else if (this.transform.position.x >= 2.5f &&               //2
                     this.transform.position.x <= 3.4f &&               //4
                     this.transform.position.y >= -0.5f &&              //3
                     this.transform.position.y <= 0.5f)
            {
                apparitionFuture();
            }
        }
        if (Input.GetKeyDown("q") && this.gameObject.GetComponent <SpriteRenderer>().sprite == notePerteVieJaune ||
            Input.GetKeyDown("w") && this.gameObject.GetComponent <SpriteRenderer>().sprite == notePerteVieRouge ||
            Input.GetKeyDown("e") && this.gameObject.GetComponent <SpriteRenderer>().sprite == notePerteVieBleu ||
            Input.GetKeyDown("r") && this.gameObject.GetComponent <SpriteRenderer>().sprite == notePerteVieVert ||
            Input.GetKeyDown("t") && this.gameObject.GetComponent <SpriteRenderer>().sprite == notePerteVieOrange)
        {
            if (!(triggerP1G.verifTrigger1G &&
                  triggerP4G.verifTrigger4G &&
                  triggerP3G.verifTrigger3G &&
                  triggerP2G.verifTrigger2G))
            {
                if (timeRemainingVieG == 0)
                {
                    timeRemainingVieG   += 2500;
                    vieScriptG.vieValue -= 1;
                    combo = 1;
                }
            }
            else if (this.transform.position.x <= -2.5f &&               //2
                     this.transform.position.x >= -3.4f &&               //4
                     this.transform.position.y >= -0.5f &&               //3
                     this.transform.position.y <= 0.5f)
            {
                ChangeSprite(notePerteVieTouche);
                if (timeRemainingVieG == 0)
                {
                    timeRemainingVieG   += 2500;
                    vieScriptG.vieValue -= 1;
                    combo = 1;
                }
            }
        }
        else if (Input.GetKeyDown("q") && this.gameObject.GetComponent <SpriteRenderer>().sprite == noteRalentiJaune ||
                 Input.GetKeyDown("w") && this.gameObject.GetComponent <SpriteRenderer>().sprite == noteRalentiRouge ||
                 Input.GetKeyDown("e") && this.gameObject.GetComponent <SpriteRenderer>().sprite == noteRalentiBleu ||
                 Input.GetKeyDown("r") && this.gameObject.GetComponent <SpriteRenderer>().sprite == noteRalentiVert ||
                 Input.GetKeyDown("t") && this.gameObject.GetComponent <SpriteRenderer>().sprite == noteRalentiOrange)
        {
            if (!(triggerP1G.verifTrigger1G &&
                  triggerP4G.verifTrigger4G &&
                  triggerP3G.verifTrigger3G &&
                  triggerP2G.verifTrigger2G))
            {
                if (timeRemainingVieG == 0)
                {
                    timeRemainingVieG   += 2500;
                    vieScriptG.vieValue -= 1;
                    combo = 1;
                }
            }
            else if (this.transform.position.x <= -2.5f &&               //2
                     this.transform.position.x >= -3.4f &&               //4
                     this.transform.position.y >= -0.5f &&               //3
                     this.transform.position.y <= 0.5f)
            {
                ChangeSprite(noteRalentiTouche);
                timeRLG += 1000;
                timeRemainingRalentiG      += 1000;
                mouvementRoueD.boostVitesse = -0.01f;
            }
        }
        else if (Input.GetKeyDown("q") && this.gameObject.GetComponent <SpriteRenderer>().sprite == noteAccelerationJaune ||
                 Input.GetKeyDown("w") && this.gameObject.GetComponent <SpriteRenderer>().sprite == noteAccelerationRouge ||
                 Input.GetKeyDown("e") && this.gameObject.GetComponent <SpriteRenderer>().sprite == noteAccelerationBleu ||
                 Input.GetKeyDown("r") && this.gameObject.GetComponent <SpriteRenderer>().sprite == noteAccelerationVert ||
                 Input.GetKeyDown("t") && this.gameObject.GetComponent <SpriteRenderer>().sprite == noteAccelerationOrange)
        {
            if (!(triggerP1G.verifTrigger1G &&
                  triggerP4G.verifTrigger4G &&
                  triggerP3G.verifTrigger3G &&
                  triggerP2G.verifTrigger2G))
            {
                if (timeRemainingVieG == 0)
                {
                    timeRemainingVieG   += 2500;
                    vieScriptG.vieValue -= 1;
                    combo = 1;
                }
            }
            else if (this.transform.position.x <= -2.5f &&               //2
                     this.transform.position.x >= -3.4f &&               //4
                     this.transform.position.y >= -0.5f &&               //3
                     this.transform.position.y <= 0.5f)
            {
                ChangeSprite(noteAccelerationTouche);
                timeACG += 1000;
                timeRemainingAccelerationG += 1000;
                mouvementRoueD.boostVitesse = 0.01f;
            }
        }
        else if (Input.GetKeyDown("q") && this.gameObject.GetComponent <SpriteRenderer>().sprite == yellowNote ||
                 Input.GetKeyDown("w") && this.gameObject.GetComponent <SpriteRenderer>().sprite == redNote ||
                 Input.GetKeyDown("e") && this.gameObject.GetComponent <SpriteRenderer>().sprite == blueNote ||
                 Input.GetKeyDown("r") && this.gameObject.GetComponent <SpriteRenderer>().sprite == greenNote ||
                 Input.GetKeyDown("t") && this.gameObject.GetComponent <SpriteRenderer>().sprite == orangeNote)
        {
            if (!(triggerP1G.verifTrigger1G &&
                  triggerP4G.verifTrigger4G &&
                  triggerP3G.verifTrigger3G &&
                  triggerP2G.verifTrigger2G))
            {
                //ChangeSprite(noteErreur);
                //Debug.Log("affiche X");

                if (timeRemainingVieG == 0)
                {
                    timeRemainingVieG   += 2500;
                    vieScriptG.vieValue -= 1;
                    combo = 1;
                }
            }
            else if (this.transform.position.x <= -2.5f &&               //2
                     this.transform.position.x >= -3.4f &&               //4
                     this.transform.position.y >= -0.5f &&               //3
                     this.transform.position.y <= 0.5f)
            {
                switch (combo)
                {
                case 1:
                    if (this.gameObject.GetComponent <SpriteRenderer>().sprite != score10)
                    {
                        scoreScriptG.scoreValue += 10;
                        ChangeSprite(score10);
                        combo += 1;
                    }
                    break;

                case 2:
                    if (this.gameObject.GetComponent <SpriteRenderer>().sprite != score20)
                    {
                        scoreScriptG.scoreValue += 20;
                        ChangeSprite(score20);
                        combo += 1;
                    }
                    break;

                case 3:
                    if (this.gameObject.GetComponent <SpriteRenderer>().sprite != score30)
                    {
                        scoreScriptG.scoreValue += 30;
                        ChangeSprite(score30);
                        combo += 1;
                    }
                    break;

                case 4:
                    if (this.gameObject.GetComponent <SpriteRenderer>().sprite != score40)
                    {
                        scoreScriptG.scoreValue += 40;
                        ChangeSprite(score40);
                        combo += 1;
                    }
                    break;

                case 5:
                    if (this.gameObject.GetComponent <SpriteRenderer>().sprite != score50)
                    {
                        scoreScriptG.scoreValue += 50;
                        ChangeSprite(score50);
                    }
                    break;
                }
            }
        }

        // De la 5 vers la 6
        if (this.transform.position.x != -8.609f &&
            this.transform.position.y != -2.39f &&
            isTargetTwoReached == false)
        {
            transform.position = Vector3.MoveTowards(transform.position, positionCible2.position, step);
        }

        // De la 6 vers la 7
        else if (this.transform.position.x != -9.485f &&
                 this.transform.position.y != 0.007f &&
                 isTargetThreeReached == false)
        {
            // Quand la note arrive sur le point 7
            if (!isClonedThisRow)
            {
                // Génère une nouvelle note sur le point 5
                Instantiate(this, new Vector3(-6.198f, -3.198f, 4.0f), Quaternion.identity);
            }
            isClonedThisRow    = true;
            transform.position = Vector3.MoveTowards(transform.position, positionCible3.position, step);
            isTargetTwoReached = true;
        }

        // De la 7 vers la 8
        else if (this.transform.position.x != -8.518f &&
                 this.transform.position.y != 2.369f &&
                 isTargetFourReached == false)
        {
            transform.position   = Vector3.MoveTowards(transform.position, positionCible4.position, step);
            isTargetThreeReached = true;
        }

        // De la 8 vers la 1
        else if (this.transform.position.x != -6.201f &&
                 this.transform.position.y != 3.276f &&
                 isTargetFiveReached == false)
        {
            transform.position  = Vector3.MoveTowards(transform.position, positionCible5.position, step);
            isTargetFourReached = true;
        }

        // De la 1 vers la 2
        else if (this.transform.position.x != -3.825f &&
                 this.transform.position.y != 2.339f &&
                 isTargetSixReached == false)
        {
            transform.position  = Vector3.MoveTowards(transform.position, positionCible6.position, step);
            isTargetFiveReached = true;
        }

        // De la 2 vers la 3
        else if (this.transform.position.x != -2.948f &&
                 this.transform.position.y != -0.052f &&
                 isTargetSevenReached == false)
        {
            transform.position = Vector3.MoveTowards(transform.position, positionCible7.position, step);
            isTargetSixReached = true;
        }

        // De la 3 vers la 4
        else if (this.transform.position.x != -3.912f &&
                 this.transform.position.y != -2.417f &&
                 isTargetEightReached == false)
        {
            transform.position   = Vector3.MoveTowards(transform.position, positionCible8.position, step);
            isTargetSevenReached = true;
        }

        // Bouge de la position 4 vers la position 5
        else if (this.transform.position.x != -6.198f &&
                 this.transform.position.y != -3.198f &&
                 isTargetOneReached == false)
        {
            if (this.gameObject.GetComponent <SpriteRenderer>().sprite != score10 &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != score20 &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != score30 &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != score40 &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != score50 &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != noteAccelerationTouche &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != noteRalentiTouche &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != notePerteVieBleu &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != notePerteVieJaune &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != notePerteVieOrange &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != notePerteVieRouge &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != notePerteVieVert &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != notePerteVieTouche &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != noteInitiale &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != notePrehistoire &&
                this.gameObject.GetComponent <SpriteRenderer>().sprite != noteFuture)
            {
                if (timeRemainingVieG == 0)
                {
                    timeRemainingVieG   += 5000;
                    vieScriptG.vieValue -= 1;
                    combo = 1;
                }
            }
            transform.position   = Vector3.MoveTowards(transform.position, positionCible.position, step);
            isTargetEightReached = true;
        }
        else
        {
            DestroyAll();
        }
    }
Example #25
0
    private void FollowTarget(Transform followingTransform)
    {
        Vector3 targetPos = _targetTransform.position;

        followingTransform.position = Vector3.MoveTowards(followingTransform.position, targetPos, _followingSpeed);
    }
Example #26
0
    private void Update()
    {
        lock (Lock)
        {
            if (AttachedGameObject != null)
            {
                AttachedGameObject.transform.localPosition = VolatilePosition;
                AttachedGameObject.transform.localRotation = VolatileRotation;
                AttachedGameObject.transform.localScale    = VolatileScale;

                cameraCurrentPosition = transform.localPosition;
                if (VoiceCommandQueue.Count > 0)
                {
                    var voiceCommand = VoiceCommandQueue.Dequeue();

                    switch (voiceCommand)
                    {
                    case "forward":
                        cameraTargetPosition += Vector3.forward * MOVEMENT_SCALE;
                        break;

                    case "backward":
                        cameraTargetPosition += Vector3.back * MOVEMENT_SCALE;
                        break;

                    case "up":
                        cameraTargetPosition += Vector3.up * MOVEMENT_SCALE;
                        break;

                    case "down":
                        cameraTargetPosition += Vector3.down * MOVEMENT_SCALE;
                        break;

                    case "right":
                        cameraTargetPosition += Vector3.right * MOVEMENT_SCALE;
                        break;

                    case "left":
                        cameraTargetPosition += Vector3.left * MOVEMENT_SCALE;
                        break;

                    case "body":
                        cameraTargetPosition = CAMERA_BODY_POSITION;
                        break;

                    case "face":
                        cameraTargetPosition = CAMERA_FACE_POSITION;
                        break;

                    default:
                        throw new NotImplementedException();
                    }
                }
                transform.localPosition = Vector3.MoveTowards(cameraCurrentPosition, cameraTargetPosition,
                                                              MAX_DISTANCE_DELTA);

                if (VisemeQueue.Count > 0)
                {
                    var viseme = VisemeQueue.Dequeue();

                    AttachedAnimator.SetInteger("VisemeID", (int)viseme);
                }

                while (KinectBodyQueue.Count > KINECT_BODY_QUEUE_SIZE)
                {
                    KinectBodyQueue.Dequeue();
                }
                if (KinectBodyQueue.Count > 0)
                {
                    var kinectBody = MoCapBodyFrame.Average(KinectBodyQueue.ToArray());

                    if (kinectBody.SkeletonTransforms != null && kinectBody.SkeletonTransforms.Length > 0)
                    {
                        foreach (MoCapKinectBone kinectBone in Enum.GetValues(typeof(MoCapKinectBone)))
                        {
                            if (MoCapBoneMapper.IsValidKinectBone(kinectBone))
                            {
                                var mecanimBone = MoCapBoneMapper.Kinect2Mecanim(kinectBone);

                                if (MoCapBoneMapper.IsValidMecanimBone(mecanimBone))
                                {
                                    var humanBodyBone   = (HumanBodyBones)mecanimBone;
                                    var mecanimBoneName = mecanimBone.ToString().ToLower();
                                    var boneTransform   = AttachedAnimator.GetBoneTransform(humanBodyBone);

                                    if (boneTransform != null)
                                    {
                                        var localRotation = MoCapBoneMapper.LocalRotation(ref kinectBody,
                                                                                          kinectBone);

                                        boneTransform.localRotation = new Quaternion(localRotation.X, localRotation.Y,
                                                                                     localRotation.Z, localRotation.W);
                                    }
                                }
                            }
                        }
                    }
                }

                while (KinectFaceQueue.Count > KINECT_FACE_QUEUE_SIZE)
                {
                    KinectFaceQueue.Dequeue();
                }
                if (KinectFaceQueue.Count > 0)
                {
                    MoCapFaceFrame kinectFace;

                    kinectFace = MoCapFaceFrame.Average(KinectFaceQueue.ToArray());

                    var headTransform = AttachedAnimator.GetBoneTransform(HumanBodyBones.Head);

                    var headRotation = new Quaternion(-kinectFace.FaceTransform.Rotation.X,
                                                      kinectFace.FaceTransform.Rotation.Y, kinectFace.FaceTransform.Rotation.Z,
                                                      kinectFace.FaceTransform.Rotation.W);

                    headTransform.localRotation = headRotation;

                    foreach (
                        MoCapKinectFacialExpression kinectFacialExpression in
                        Enum.GetValues(typeof(MoCapKinectFacialExpression)))
                    {
                        if (MoCapFacialExpressionMapper.IsValidKinectFacialExpression(kinectFacialExpression))
                        {
                            var kinectWeight = kinectFace.ExpressionWeights[(int)kinectFacialExpression];

                            MoCapMixamoFacialExpression mixamoFacialExpression;
                            float mixamoWeight;
                            MoCapFacialExpressionMapper.Kinect2Mixamo(kinectFacialExpression, kinectWeight,
                                                                      out mixamoFacialExpression, out mixamoWeight);

                            if (MoCapFacialExpressionMapper.IsValidMixamoFacialExpression(mixamoFacialExpression))
                            {
                                AttachedBodySkinnedMeshRenderer.SetBlendShapeWeight((int)mixamoFacialExpression,
                                                                                    mixamoWeight);

                                if (mixamoFacialExpression == MoCapMixamoFacialExpression.Blink_Left ||
                                    mixamoFacialExpression == MoCapMixamoFacialExpression.Blink_Right)
                                {
                                    AttachedEyelashesSkinnedMeshRenderer.SetBlendShapeWeight(
                                        (int)mixamoFacialExpression, mixamoWeight);
                                }
                            }
                        }
                    }
                }
            }
        }
    }