Exemple #1
0
 private void Move()
 {
     rb.velocity = new Vector2(Mathf.Lerp(0, Input.GetAxis("Horizontal") * acceleration, _maxSpeed),
                               Mathf.Lerp(0, Input.GetAxis("Vertical") * acceleration, _maxSpeed));
     //if (rb.velocity.x != 0 || rb.velocity.y != 0) animations.Walk(rb);//new Vector2(_input.Horizontal, _input.Vertical));
     if (_input.Horizontal != 0 || _input.Vertical != 0)
     {
         animations.Walk(new Vector2(_input.Horizontal, _input.Vertical));
     }
     else
     {
         animations.Idle();
     }
 }
    IEnumerator WaitForGun()
    {
        yield return(new WaitForSeconds(.5f)); //Wait for gun to end

        anim.Idle();
        StopCoroutine(WaitForGun());
    }
Exemple #3
0
    void FixedUpdate()
    {
        float h = Input.GetAxisRaw("Horizontal");
        float v = Input.GetAxisRaw("Vertical");

        if (h == 0 && v == 0)
        {
            anim.Idle();
        }
        else if (h != 0 || v != 0)
        {
            anim.Running();
        }

        Move(h, v);

        if (!(h == 0 && v == 0))
        {
            Turning();
        }
    }
Exemple #4
0
    public void MoveCharacter(float h, float v, bool Sprint)
    {
        Vector3 DirVector = new Vector3();

        DirVector.x = h;
        DirVector.y = 0f;
        DirVector.z = v;
        DirVector   = DirVector.normalized;
        //Change speed
        if (v != 0)
        {
            if (Sprint)
            {
                speed = MaxVelocity;
                anim.Running();
            }
            else
            {
                speed = regVelocity;
                anim.Walking();
            }
        }
        else
        {
            speed = regVelocity;
            anim.Idle();
        }
        if (ENABLED)
        {
            if (Vector3.Magnitude(player.velocity) < MaxVelocity)
            {
                player.SimpleMove(transform.forward * v * Time.deltaTime * speed);
                player.SimpleMove(transform.right * h * Time.deltaTime * speed);
            }
        }
    }
Exemple #5
0
    void  Controls()
    {
        //  Debug.Log("Current Rotation: " + transform.rotation.y);
        if (Input.GetKey(KeyCode.A))
        {
            // Move left
            if (!this.GetComponent <AudioSource>().isPlaying&& stepTimer <= 0)
            {
                this.GetComponent <AudioSource>().Play();
                stepTimer = 0.65f;
            }
            else
            {
                stepTimer -= Time.deltaTime;
            }
            Scene scene = SceneManager.GetActiveScene();
            if (scene.name == "Hotel" || scene.name == "TrainStation" || scene.name == "trainMoving")
            {
                transform.Translate(-transform.forward * mov_speed * Time.deltaTime);
            }
            else
            {
                transform.Translate(-transform.right * mov_speed * Time.deltaTime);
            }



            if (transform.rotation.y <= 0.5f && transform.rotation.y >= -0.5f)
            {
                //   Debug.Log("Walking normal");

                p_anim.WalkBackwards();
            }
            else
            {
                // Debug.Log("Walking backwards");
                p_anim.Walking();
            }
        }
        if (Input.GetKey(KeyCode.D))
        {
            if (!this.GetComponent <AudioSource>().isPlaying&& stepTimer <= 0)
            {
                this.GetComponent <AudioSource>().Play();
                stepTimer = 0.65f;
            }
            else
            {
                stepTimer -= Time.deltaTime;
            }

            // Move right
            Scene scene = SceneManager.GetActiveScene();
            if (scene.name == "Hotel" || scene.name == "TrainStation" || scene.name == "trainMoving")
            {
                transform.Translate(transform.forward * mov_speed * Time.deltaTime);
            }
            else
            {
                transform.Translate(transform.right * mov_speed * Time.deltaTime);
            }


            if (scene.name == "Field")
            {
                if (transform.rotation.y <= 0.5f && transform.rotation.y >= -0.5f)
                {
                    p_anim.WalkBackwards();
                }
                else
                {
                    p_anim.Walking();
                }
            }
            else
            {
                if (transform.rotation.y <= 0.5f && transform.rotation.y >= -0.5f)
                {
                    p_anim.Walking();
                }
                else
                {
                    p_anim.WalkBackwards();
                }
            }
        }
        if (Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.D))
        {
            p_anim.Idle();
            this.GetComponent <AudioSource>().Stop();
        }
        //if((Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.W)) && isOnGround) // && isOnGround
        //{
        //    // Jump
        //    p_rigidbody.AddForce(Vector3.up * mov_jumpDistance, ForceMode.Impulse);
        //}
    }