// Update is called once per frame
    void FixedUpdate()
    {
        Vector2 moveVector = new Vector2();
        Vector2 currentPos = rbody.position;

        // Player-controlled movement
        // Vector2 moveVector = getMovementInput();

        //Game-controlled movement
        if (path != null && path.Count > 0)
        {
            Vector2 destination = IsoToRealConverter.IsometricToRealCoordinates(path[0]);
            Vector2 desiredMove = destination - rbody.position;

            if (desiredMove.magnitude < .05)
            {
                path.RemoveAt(0);
            }
            if (path.Count > 0)
            {
                destination = IsoToRealConverter.IsometricToRealCoordinates(path[0]);
                desiredMove = destination - rbody.position;
                moveVector  = desiredMove.normalized;
            }
        }

        // Render the movement
        Vector2 movement = moveVector * movementSpeed;
        Vector2 newPos   = currentPos + movement * Time.fixedDeltaTime;

        isoRenderer.SetDirection(movement);
        rbody.MovePosition(newPos);
    }
 public void AttackPerFrame(Vector2 inputVector, Vector2 movement, IsometricCharacterRenderer isoRenderer)
 {
     if (currentAttackState == IsometricCharacterRenderer.States.none)
     {
         isoRenderer.SetDirection(movement);
     }
     if (currentAttackState > animatedAttackState)
     {
         animatedAttackState += 1;
         isoRenderer.AttackDirection(inputVector, animatedAttackState);
         attackCounter = 0;
         playerAttackHitbox.HitboxDealDamage((int)animatedAttackState - 1);
     }
     else if (currentAttackState > 0)
     {
         if (attackCounter > attackFrames[(int)currentAttackState - 1])
         {
             currentAttackState  = IsometricCharacterRenderer.States.none;
             animatedAttackState = IsometricCharacterRenderer.States.none;
             attackCounter       = 0;
         }
         else
         {
             attackCounter++;
         }
     }
 }
Beispiel #3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //m_ownedActor.AddMovementInput(MathUtils.ForwardVector.Rotate(m_ownedActor.Rotation), 1);

        Vector2 groupingAcc, separationAcc, cohesionAcc;

        BoidsManager.Instance.BoidsGSC(gameObject, out groupingAcc, out separationAcc, out cohesionAcc);
        Vector2 fleeingAcc = BoidsManager.Instance.AvoidPredator(gameObject);

        //Vector2 borderBouncingAcc = BoidsManager.BorderBouncing(gameObject);

        // POLISH: if near to predator, break the grouping beahviour
        // and increase the border bouncing in order to better avoid walls in panic.
        if (fleeingAcc != Vector2.zero)
        {
            groupingAcc *= -1.0f;
            bIsFleeing   = true;
            //borderBouncingAcc *= 5.0f;
            AudioManager.Instance.PlayHumanYellingRandomAudio(transform.position);
        }
        else
        {
            bIsFleeing = false;
        }

        float   randV    = Mathf.Cos(Time.timeSinceLevelLoad);
        Vector2 forceSum = new Vector2(Random.Range(-randV, randV), Random.Range(-randV, randV)) * Time.deltaTime + groupingAcc + separationAcc + cohesionAcc + fleeingAcc;

        rbody.AddForce(forceSum * BoidsManager.Instance.Data.BoidSpeed, ForceMode2D.Force);
        isoRenderer.SetDirection(rbody.velocity, rbody.velocity);
        rbody.velocity = Vector2.ClampMagnitude(rbody.velocity, BoidsManager.Instance.Data.MaxVelocity);
    }
 void Start()
 {
     _rbody       = GetComponent <Rigidbody2D>();
     _isoRenderer = GetComponentInChildren <IsometricCharacterRenderer>();
     _isoRenderer.SetDirection(Vector2.zero);
     MoveTo(0);
 }
Beispiel #5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector2 currentPos = rbody.position;

        //Check if pause menu is active or if mouse is over pause button
        if (Input.GetMouseButton(0) && canMove && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
        {
            transform.position = Vector2.MoveTowards(transform.position, mousePosition, movementSpeed * Time.deltaTime);
            isoRenderer.SetDirection(mousePosition);
        }
        if (!Input.GetMouseButton(0))
        {
            isoRenderer.SetDirection(new Vector2(0, 0));
        }
    }
    public void Move(Vector2 direction)
    {
        direction = direction.normalized;                                                  //Clamp the magnitude of the inputVector
        isoRenderer.SetDirection(direction);                                               //Set the character's sprite direction
        Vector2 newPos = rbody.position + direction * movementSpeed * Time.fixedDeltaTime; //Set new pos toward input

        rbody.MovePosition(newPos);
    }
Beispiel #7
0
 private void HandleMovement()
 {
     Vector2 currentPos = rb2D.position;
     Vector2 inputVector = velocity;
     inputVector = Vector2.ClampMagnitude(inputVector, 1);
     Vector2 movement = inputVector * movementSpeed;
     Vector2 newPos = currentPos + movement * Time.fixedDeltaTime;
     isoRenderer.SetDirection(movement);
     rb2D.MovePosition(newPos);
 }
Beispiel #8
0
    // Update is called once per frame
    void Update()
    {
        Vector3 direction = player.position - transform.position;
        float   angle     = Mathf.Atan2(direction.y, direction.x);// * Mathf.Rad2Deg;

        rb.rotation = angle;
        direction.Normalize();
        movement = direction;
        isoRenderer.SetDirection(movement);
    }
Beispiel #9
0
    // Update is called once per frame
    void FixedUpdate()
    {
        isoRenderer.AverageMaxSpeed = movementSpeed;

        Vector2 direction = new Vector2(Input.GetAxisRaw("RightHorizontal"), Input.GetAxisRaw("RightVertical"));

        direction = direction * AngularSpeed;

        Vector2 currentPos      = rbody.position;
        float   horizontalInput = Input.GetAxis("Horizontal");
        float   verticalInput   = Input.GetAxis("Vertical");
        Vector2 inputVector     = new Vector2(horizontalInput, verticalInput);

        inputVector = Vector2.ClampMagnitude(inputVector, 1);
        Vector2 movement = inputVector * movementSpeed;
        Vector2 newPos   = currentPos + movement * Time.fixedDeltaTime;

        rbody.MovePosition(newPos);

        if (direction != Vector2.zero)
        {
            if (LastDirection != direction)
            {
                LastDirection = direction;
                isoRenderer.SetDirection(direction, movement);
                //OwnTransform.rotation = Quaternion.Lerp(OwnTransform.rotation, Quaternion.LookRotation(LastDirection), Time.deltaTime * AngularSpeed);
            }
        }
        else if (MousePosition != Input.mousePosition)
        {
            direction = Input.mousePosition - Camera.main.WorldToScreenPoint(transform.position);
            //OwnTransform.rotation = Quaternion.Lerp(OwnTransform.rotation, Quaternion.LookRotation(direction), Time.deltaTime * AngularSpeed);
            MousePosition = Input.mousePosition;
            isoRenderer.SetDirection(direction, movement);
        }

        if (direction != Vector2.zero)
        {
            lastWantedDirection = direction;
        }
    }
 protected void Update()
 {
     isoRenderer.SetDirection(rbody.velocity.normalized);
     if (canBeBaited)
     {
         CheckBait();
     }
     if (staggerTag.Length > 0)
     {
         CheckStagger();
     }
 }
    public bool MoveTo(float position, Action onMoveEnd = null)
    {
        if (IsMoveCooldown())
        {
            return(false);
        }

        _moving = true;

        _onMoveEnd = onMoveEnd;

        Vector2 inputVector = new Vector2(position * 0.5f, position * 0.25f);

        _prevPosition   = _rbody.position;
        _targetPosition = inputVector;

        _isoRenderer.SetDirection(new Vector2(1, 0.5f));

        _timeSinceLastMove = 0;

        return(true);
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        if (isChatting == 0)
        {
            Vector2 currentPos      = rbody.position;
            float   horizontalInput = Input.GetAxis("Horizontal");
            float   verticalInput   = Input.GetAxis("Vertical");
            Vector2 inputVector     = new Vector2(horizontalInput, verticalInput);
            inputVector = Vector2.ClampMagnitude(inputVector, 1);
            Vector2 movement = inputVector * movementSpeed;

            if (Input.GetKeyDown(KeyCode.Z))
            {
                Vector2 newPos1 = currentPos + 30 * movement * Time.fixedDeltaTime;
                Instantiate(attack, newPos1, Quaternion.identity);
                return;
            }

            if (Input.GetKeyDown(KeyCode.X))
            {
                Vector2 newPos1 = currentPos + 50 * movement * Time.fixedDeltaTime;
                isoRenderer.SetDirection(movement);
                rbody.MovePosition(newPos1);
                return;
            }

            if (Input.GetKeyDown(KeyCode.C))
            {
                Vector2 newPos1 = currentPos + 30 * movement * Time.fixedDeltaTime;
                Instantiate(attack1, newPos1, Quaternion.identity);
                return;
            }

            Vector2 newPos = currentPos + movement * Time.fixedDeltaTime;
            isoRenderer.SetDirection(movement);
            rbody.MovePosition(newPos);
        }
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector2 currentPos      = rbody.position;
        float   horizontalInput = Input.GetAxis("Horizontal");
        float   verticalInput   = Input.GetAxis("Vertical");
        Vector2 inputVector     = new Vector2(horizontalInput, verticalInput);

        inputVector = Vector2.ClampMagnitude(inputVector, 1);
        Vector2 movement = inputVector * movementSpeed;
        Vector2 newPos   = currentPos + movement * Time.fixedDeltaTime;

        isoRenderer.SetDirection(movement);
        rbody.MovePosition(newPos);
    }
    public void AttackPerFrame2(Vector2 inputVector, Vector2 movement, IsometricCharacterRenderer isoRenderer)
    {
        int curL = currentAttackString.Length;
        int aniL = animatedAttackString.Length;
        int id;

        if (animatedAttackString == "")
        {
            isoRenderer.SetDirection(movement);
        }
        if (curL > aniL)
        {
            animatedAttackString = currentAttackString.Substring(0, aniL + 1);
            id = attackHash.getKeyIndex(animatedAttackString);
            if (id != -1)
            {
                isoRenderer.AttackDirection(inputVector, stateHash[id]);
                PlaySound(animatedAttackString.Length);
                DoSpecial(inputVector, isoRenderer, animatedAttackString);
            }
            else
            {
                resetAttackString();
            }
            attackCounter = 0;
            if (id != -1)
            {
                playerAttackHitbox.HitboxDealDamage(id);
            }
        }
        if (curL > 0)
        {
            id = attackHash.getKeyIndex(animatedAttackString);
            if (id != -1)
            {
                if (attackCounter > attackFrames[id])
                {
                    resetAttackString();
                }
                else
                {
                    attackCounter++;
                }
            }
            else
            {
                resetAttackString();
            }
        }
    }
Beispiel #15
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (GameManager.instance.puzzleActive || GameManager.instance.disableMovement)
        {
            isoRenderer.SetDirection(new Vector2(0, 0));
            return;
        }

        Vector3 currentPos      = rbody.position;
        float   horizontalInput = Input.GetAxis("Horizontal");
        float   verticalInput   = Input.GetAxis("Vertical");
        Vector3 inputVector     = new Vector3(horizontalInput, verticalInput, 0);

        if (turnMovement)
        {
            inputVector = inputVector.Rotate(-45f, Vector3.forward);
        }
        inputVector.x *= moveOffset;
        inputVector    = Vector3.ClampMagnitude(inputVector, 1);
        Vector3 movement = inputVector * movementSpeed;
        Vector3 newPos   = currentPos + movement * Time.fixedDeltaTime;

        isoRenderer.SetDirection(movement);
        rbody.MovePosition(newPos);


        //if ( (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0 ) && needNewSound)
        //{
        //    currentAudio.clip = steps[Random.Range(0, steps.Length)];
        //    currentAudio.volume = 0.5f;
        //    currentAudio.Play();
        //    needNewSound = false;
        //    StartCoroutine(WaitForFootStep());


        //}
    }
Beispiel #16
0
    private void Update()
    {
        if (!playerStatus.dead && !playerAttackS.isWipping && !playerStatus.isStunned)
        {
            horizontalInput = Input.GetAxis("Horizontal");
            verticalInput   = Input.GetAxis("Vertical");

            if (Input.GetKey(KeyCode.LeftShift))
            {
                movementSpeed = runSpeed;
            }
            else
            {
                movementSpeed = walkSpeed;
            }
        }
        else
        {
            horizontalInput = 0;
            verticalInput   = 0;
            isoRenderer.SetDirection(Vector2.zero);
            movementSpeed = 0.0f;
        }
    }
Beispiel #17
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Vector2 currentPos = rbody.position;
        // float horizontalInput = Input.GetAxis("Horizontal");
        // float verticalInput = Input.GetAxis("Vertical");
        Vector2 inputVector = (destination - currentPos);

        if (inputVector.magnitude < 0.5f)
        {
            isoRenderer.SetDirection(Vector2.zero);
            if (path.Count > 0)
            {
                SetDestination(path[0]);
                path.RemoveAt(0);
            }
            return;
        }
        inputVector = Vector2.ClampMagnitude(inputVector, 1);
        Vector2 movement = inputVector * movementSpeed;
        Vector2 newPos   = currentPos + movement * Time.fixedDeltaTime;

        isoRenderer.SetDirection(movement);
        rbody.MovePosition(newPos);
    }
Beispiel #18
0
    void Move()
    {
        Vector2 currentPos      = rbody.position;
        float   horizontalInput = joystick.Horizontal;
        float   verticalInput   = joystick.Vertical;
        Vector2 inputVector     = new Vector2(horizontalInput, verticalInput);

        inputVector = Vector2.ClampMagnitude(inputVector, 1);
        Vector2 movement = inputVector * movementSpeed;
        Vector2 newPos   = currentPos + movement * Time.fixedDeltaTime;

        isoRenderer.SetDirection(movement);
        rbody.MovePosition(newPos);

        MathfCalculate.DegreeFromVector2(inputVector);
        //Debug.Log(inputVector +" Degree : "+ MathfCalculate.DegreeFromVector2(inputVector).ToString());
        diraxis = inputVector;
        angle   = MathfCalculate.DegreeFromVector2(inputVector);
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        // ** MOVE SPLASH ** //
        if (Input.anyKey)
        {
            Move();
        }

        //Vector2 currentPos = rbody.position;
        float   horizontalInput = Input.GetAxis("HorizontalKey");
        float   verticalInput   = Input.GetAxis("VerticalKey");
        Vector2 inputVector     = new Vector2(horizontalInput, verticalInput);

        //inputVector = Vector2.ClampMagnitude(inputVector, 1);
        //Vector2 movement = inputVector * movementSpeed;
        //Vector2 newPos = currentPos + movement * Time.fixedDeltaTime;
        isoRenderer.SetDirection(inputVector);
        //rbody.MovePosition(newPos);
    }
Beispiel #20
0
    private void MovementFunction(int playerNum)
    {
        Vector2 currentPos      = rbody.position;
        float   horizontalInput = Input.GetAxis(horizontalArray[playerNum]);
        float   verticalInput   = Input.GetAxis(verticalArray[playerNum]);

        Vector2 inputVector = new Vector2(horizontalInput, verticalInput);

        currentDir = inputVector;

        if (currentDir != Vector2.zero)
        {
            lastDir = currentDir;
        }


        inputVector = Vector2.ClampMagnitude(inputVector, 1); //1 might have to be baseMovementSpeed instead. clamp prevents diagonal movement being faster
        Vector2 movement = inputVector * currentSpeed;
        Vector2 newPos   = currentPos + movement * Time.fixedDeltaTime;

        if (canAnimate)
        {
            isoRenderer.SetDirection(movement);
        }
        if (newPos != currentPos)
        {
            rbody.MovePosition(newPos);

            stepTimer -= Time.deltaTime;
            if (stepTimer <= 0)
            {
                if (acFootsteps.Length > 0)
                {
                    audio.PlayOneShot(acFootsteps[Random.Range(0, acFootsteps.Length)]);
                    stepTimer = stepDelay;
                }
            }
            //play walk audio
        }
    }
Beispiel #21
0
    // Update is called once per frame
    void Update()
    {
        DisableMovementIfAtTarget();

        if (path == null || targetReached)
        {
            return;
        }

        Vector2 nextPosition = (Vector2)path.vectorPath[currentWaypoint];
        Vector2 direction    = Vector2.ClampMagnitude((nextPosition - (Vector2)transform.position), 1);

        isoRenderer.SetDirection(direction);
        transform.position = Vector2.MoveTowards(transform.position, nextPosition, movementSpeed * Time.deltaTime);

        float distance = Vector2.Distance(transform.position, path.vectorPath[currentWaypoint]);

        if (distance <= nextWaypointDistance)
        {
            currentWaypoint++;
        }
    }
 private void Start()
 {
     lookDir = new Vector2(0, -1);
     isoRenderer.SetDirection(lookDir);
 }
Beispiel #23
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!GameManager.inCabane)
        {
            if (Input.GetKey(KeyCode.Space))
            {
                movementSpeed = 2f;
                gameObject.GetComponent <audioPlayer>().setPitch(2.0f);
            }
            else
            {
                movementSpeed = 1f;
                gameObject.GetComponent <audioPlayer>().setPitch(1.0f);
            }
            if (Input.GetMouseButton(0))
            {
                // Pour le déplacement au clic, en cours de réal
                //               moveWithClick = true;
                //               targetPosition =  Camera.main.ScreenToWorldPoint(Input.mousePosition);
                //              Debug.Log("Clic position to reach : " + targetPosition);
            }
            Vector2 currentPos = rbody.position;
            Vector2 movement   = new Vector2();


            if (Input.anyKey && !Input.GetMouseButton(0))
            {
                moveWithClick = false;
            }

            if (moveWithClick == false)
            {
                float   horizontalInput = Input.GetAxis("Horizontal");
                float   verticalInput   = Input.GetAxis("Vertical");
                Vector2 inputVector     = new Vector2(horizontalInput, verticalInput);
                inputVector = Vector2.ClampMagnitude(inputVector, 1);
                movement    = inputVector * movementSpeed;
                if (inputVector.Equals(new Vector2(0, 0)))
                {
                    GameManager.stateDeplacement = 0.033f;
                }
                else
                {
                    GameManager.stateDeplacement = movementSpeed + 0.015f;
                }
            }
            else
            {
                Vector2 directionVector = new Vector2(targetPosition.x - currentPos.x, targetPosition.y - currentPos.y);
                directionVector = Vector2.ClampMagnitude(directionVector, 1);
                movement        = directionVector * movementSpeed;
            }

            Vector2 newPos = currentPos + movement * Time.fixedDeltaTime;
            isoRenderer.SetDirection(movement);
            rbody.MovePosition(newPos);

            if (newPos == targetPosition)
            {
                moveWithClick = false;
            }
        }
    }
 void SetDirectionFromIsoRenderer(Vector2 direction)
 {
     isoRenderer.SetDirection(direction);
 }