// Update is called once per frame
 void Update()
 {
     if (Input.GetButtonDown("Jump"))
     {
         pc.Jump();
     }
     if (Input.GetAxis("Horizontal") > 0)
     {
         pc.Move(Vector2.right);
     }
     if (Input.GetAxis("Horizontal") < 0)
     {
         pc.Move(Vector2.left);
     }
 }
예제 #2
0
    // Called once per physics frame (different than render frame)
    // FixedUpdate() is typically used instead of Update() for anything involving rigidbodies/physics
    private void FixedUpdate()
    {
        //Replace these with player input
        jumpDown = (Input.GetKey(KeyCode.Space) || Input.GetKeyDown(KeyCode.Space)) && !die;
        jumpStay = false;
        die      = (GetComponent <Collider2D>().IsTouching(enemy.GetComponent <Collider2D>()) && dead == false || transform.position.y < -4);
        Adown    = Input.GetKey(KeyCode.A);
        Ddown    = Input.GetKey(KeyCode.D);
        if (Adown && Ddown)
        {
            x = 0;
        }
        else if (Adown && !dead)
        {
            x = -1;
        }
        else if (Ddown && !dead)
        {
            x = 1;
        }
        else
        {
            x = 0;
        }

        //Calls Move every physics frame.
        controller.Move(x, jumpDown, jumpStay);
        if (die)
        {
            dead = true;
            die  = false;
            controller.Die();
        }
    }
예제 #3
0
    // Update is called once per frame
    void Update()
    {
        CalculateVelocity();
        if (enableWallSliding)
        {
            HandleWallSliding();
        }

        UpdateAnimator();

        controller.Move(velocity * Time.deltaTime, directionalInput);

        if (controller.collisions.above || controller.collisions.below)
        {
            if (controller.collisions.slidingDownMaxSlope)
            {
                velocity.y += controller.collisions.slopeNormal.y * -gravity * Time.deltaTime;
            }
            else
            {
                velocity.y = 0;
            }
        }

        if (transform.position.y < minY)
        {
            Respawn();
        }
    }
예제 #4
0
    void Update()
    {
        try
        {
            gamepad = Gamepad.all[controllerNumber];

            Controller.Move(gamepad.leftStick.ReadValue());
            Vector2 RightAxis = gamepad.rightStick.ReadValue();
            gunPositioner.SetRotation(RightAxis);
            if (!Vector2isZero(RightAxis))
            {
                if (!audio.isPlaying)
                {
                    audio.Play();
                }

                isShooting = true;
            }
            else
            {
                isShooting = false;
            }
        }
        catch (Exception e)
        {
            gameObject.SetActive(false);
            Debug.Log("playercontroller: " + gameObject.name + " disabled due to device not pluged in" +
                      Gamepad.all.Count);
            return;
        }
    }
예제 #5
0
        public override void Move(Vector3 direction)
        {
            direction = Vector3.Project(direction, transform.forward);
            _controllerInstance.Move(direction.z, 0f);

            _animator.SetFloat(_motionAnimationHash, Mathf.Abs(direction.z));
        }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        if (platformerController.collisionInfo.above || platformerController.collisionInfo.below)
        {
            velocity.y = 0;
        }

        if (shouldMove)
        {
            bounds = GetComponent <Collider2D>().bounds;
            //if we are currently moving right
            if (facingRight)
            {
                if (platformerController.collisionInfo.right == false)
                {
                }
                else
                {
                    SetDirection(false);
                    Debug.Log(string.Format("Flip | Speed: {0}", speed));
                    Flip();
                }
            }

            else
            {
                if (platformerController.collisionInfo.left == false)
                {
                }
                else
                {
                    SetDirection(true);
                    Debug.Log(string.Format("Flip | Speed: {0}", speed));
                    Flip();
                }
            }

            Vector2 moveInput = new Vector2(speed, 0);
            velocity.x = moveInput.x;
        }
        velocity.y += gravity * Time.deltaTime;
        platformerController.Move(velocity * Time.deltaTime);
        if (canFire)
        {
            Vector2 direction = player.position - transform.position;
            direction.Normalize();
            Debug.DrawRay(transform.position, direction * 8, Color.red);
            RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, 8, playerMask);
            if (hit.collider != null && direction.y < 0)
            {
                if (hit.collider.gameObject.CompareTag("Player"))
                {
                    StartCoroutine("FireBelow", direction);
                }
            }
        }
    }
예제 #7
0
    // Called once per physics frame (different than render frame)
    // FixedUpdate() is typically used instead of Update() for anything involving rigidbodies/physics
    private void FixedUpdate()
    {
        seperation  = Mathf.Abs(transform.position[0] - player.transform.position[0]);
        closeEnough = (seperation < 5);

        if (GetComponent <Collider2D>().IsTouching(player.GetComponent <Collider2D>()))
        {
            x    = 0;
            dead = true;
        }

        if (transform.position.x < -9.75 || transform.position.x > 9.75)
        {
            x     = -x;
            timer = Random.Range(1f, 3f);
        }

        else if (closeEnough && dead == false)
        {
            if ((transform.position[0] - player.transform.position[0]) < 0)
            {
                x = 1;
            }
            else if ((transform.position[0] - player.transform.position[0]) > 0)
            {
                x = -1;
            }
        }

        else if (closeEnough == false)
        {
            //Taken from https://answers.unity.com/questions/770857/whats-the-most-efficient-way-to-time-events.html
            timer -= Time.deltaTime;
            if (timer < 0)
            {
                x     = -x;
                timer = Random.Range(1.5f, 4f);
            }
        }
        ;

        //Calls Move every physics frame.
        controller.Move(x, jumpDown, jumpStay);
        if (die)
        {
            controller.Die();
        }
    }
예제 #8
0
    // Update is called once per frame
    void Update()
    {
        if (platformerController.collisionInfo.above || platformerController.collisionInfo.below)
        {
            velocity.y = 0;
        }
        if (shouldMove)
        {
            Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));

            //if we want to go down ignoreOneWayCollision else don't
            platformerController.ignoreOneWayCollision = moveInput.y < 0 ? true:false;
            if (moveInput.x < 0 && facingRight)
            {
                Flip();
            }
            if (moveInput.x > 0 && !facingRight)
            {
                Flip();
            }



            if (Input.GetButtonDown("Jump") && platformerController.collisionInfo.below)
            {
                velocity.y = jumpVelocity;
                audioSource.PlayOneShot(JumpTempAudioClip);
            }
            if (Input.GetButton("Fire1") && UI_Control.isPaused == false)
            {
                if (canFire)
                {
                    StartCoroutine("FireProjectile");
                }
            }
            velocity.x  = moveInput.x * walkSpeed;
            velocity.y += gravity * Time.deltaTime;
        }

        platformerController.Move(velocity * Time.deltaTime);

        float velocityX = velocity.x;
        float velocityY = velocity.y;

        animator.SetFloat("VelocityX", Mathf.Abs(velocityX));
        animator.SetFloat("VelocityY", velocityY);
        animator.SetBool("isGrounded", platformerController.collisionInfo.below);
    }
예제 #9
0
    private void FixedUpdate()
    {
        //Replace these with AI input. It should wander until the player gets near, then chase the player.
        x        = 0;
        jumpDown = false;
        jumpStay = false;
        die      = false;

        //Calls Move every physics frame.
        controller.Move(x, jumpDown, jumpStay);

        if (die)
        {
            controller.Die();
        }
    }
예제 #10
0
    private void FixedUpdate()
    {
        //Replace these with player input
        x        = 0;
        jumpDown = false;
        jumpStay = false;
        die      = false;

        //Calls Move every physics frame.
        controller.Move(x, jumpDown, jumpStay);

        if (die)
        {
            controller.Die();
        }
    }
예제 #11
0
    // Update is called once per frame
    void Update()
    {
        if (platformerController.collisionInfo.above || platformerController.collisionInfo.below)
        {
            velocity.y = 0;
        }

        if (shouldMove)
        {
            bounds = GetComponent <Collider2D>().bounds;
            //if we are currently moving up
            if (goingUp)
            {
                if (platformerController.collisionInfo.above == false)
                {
                }
                else
                {
                    SetDirection(false);
                    Debug.Log(string.Format("Flip | Speed: {0}", speed));
                }
            }
            //if we are currently moving down
            else
            {
                if (platformerController.collisionInfo.below == false)
                {
                }
                else
                {
                    SetDirection(true);
                    Debug.Log(string.Format("Flip | Speed: {0}", speed));
                }
            }

            Vector2 moveInput = new Vector2(0, speed);
            velocity.y = moveInput.y;
        }

        platformerController.Move(velocity * Time.deltaTime);
    }
예제 #12
0
    void Update()
    {
        if (diedThisFrame)
        {
            StartCoroutine(PlayerDeath());
            diedThisFrame = false;
        }

        CalculateVelocity();

        controller.Move(velocity * Time.deltaTime, directionalInput);

        if (controller.collisions.below)
        {
            hit = true;
        }
        if (controller.collisions.above || controller.collisions.below)
        {
            velocity.y = 0;                     // To avoid "accumulating" gravity
        }
    }
예제 #13
0
    /// <summary>
    /// Handle movement of thing
    /// </summary>
    /// <param name="dt"></param>
    protected void HandleMovement(float dt, float gravMult = 1)
    {
        //Add gravity
        velocity.y -= gravity * dt * gravMult;

        //Slow down
        velocity.x = Mathf.MoveTowards(velocity.x, 0, friction * dt);

        //Move
        platformer.Move(velocity * dt);

        //Test for collisions that would stop velocity
        if (platformer.collisions.bottom || platformer.collisions.top)
        {
            velocity.y = 0;
        }
        if (platformer.collisions.right || platformer.collisions.left)
        {
            velocity.x = 0;
        }
    }
예제 #14
0
	// Update is called once per frame
	void Update ()
    {

        if (platformerController.collisionInfo.above || platformerController.collisionInfo.below)
        {
            velocity.y = 0;
        }
        
        if (shouldMove)
        {
            bounds = GetComponent<Collider2D>().bounds;
            //if we are currently moving right
            if(facingRight)
            {

                if (platformerController.collisionInfo.right == false)
                {

                    //check if we will fall more than x blocks
                    Debug.DrawRay(new Vector2(bounds.max.x, bounds.min.y), Vector2.down * 1.1f, Color.red);
                    RaycastHit2D hit = Physics2D.Raycast(new Vector2(bounds.max.x, bounds.min.y), Vector2.down, 1.1f, ground);

                    //hit ground
                    if (hit.collider != null)
                    {
                        //Debug.Log(string.Format("Hit Object: {0}", hit.collider.gameObject));

                        //Debug.Log(string.Format("Hit distance: {0}", bounds.max.x, bounds.min.y));
                        if (hit.distance > 1)
                        {
                            SetDirection(false);
                            //Debug.Log(string.Format("Flip | Speed: {0}", speed));
                            Flip();
                        }
                    }
                    else
                    {
                        SetDirection(false);
                        //Debug.Log(string.Format("Flip | Speed: {0}", speed));
                        Flip();
                    }
                }
                else
                {
                    SetDirection(false);
                    //Debug.Log(string.Format("Flip | Speed: {0}", speed));
                    Flip();
                }
            }

            else
            {
                if (platformerController.collisionInfo.left == false)
                {
                    //check if we will fall more than x blocks
                    Debug.DrawRay(new Vector2(bounds.min.x, bounds.min.y), Vector2.down * 1.1f, Color.red);
                    RaycastHit2D hit = Physics2D.Raycast(new Vector2(bounds.min.x, bounds.min.y), Vector2.down, 1.1f, ground);
                    //hit ground
                    if (hit.collider != null)
                    {

                        //Debug.Log(string.Format("Hit Object: {0}", hit.collider.gameObject));
                        Debug.Log(string.Format("Hit distance: {0}", bounds.min.x, bounds.min.y));
                        if (hit.distance > 1)
                        {
                            SetDirection(true);
                            Debug.Log(string.Format("Flip | Speed: {0}", speed));
                            Flip();

                        }

                    }
                    else
                    {
                        SetDirection(true);
                        Debug.Log(string.Format("Flip | Speed: {0}", speed));
                        Flip();

                    }

                }
                else
                {
                    SetDirection(true);
                    Debug.Log(string.Format("Flip | Speed: {0}", speed));
                    Flip();
                }
            }

        Vector2 moveInput = new Vector2(speed, 0);
        velocity.x = moveInput.x;
        }
        velocity.y += gravity * Time.deltaTime;
        platformerController.Move(velocity * Time.deltaTime);        

    }