Ejemplo n.º 1
0
    void FixedUpdate()
    {
        //grounded = Physics2D.OverlapBox(groundCheck.position, new Vector2(0.003f, 0.003f), whatIsGround);
        //grounded = Physics2D.OverlapCircle(groundCheckRight.position, groundRadius, whatIsGround);
        //if(!grounded)
        //    Physics2D.OverlapCircle(groundCheckLeft.position, groundRadius, whatIsGround);

        grounded = Physics2D.OverlapCircle(groundCheckRight.position, groundRadius, whatIsGround) ||
                   Physics2D.OverlapCircle(groundCheckLeft.position, groundRadius, whatIsGround);

        Debug.Log("Right Collision: " + Physics2D.OverlapCircle(groundCheckRight.position, groundRadius, whatIsGround));
        Debug.Log("Left Collision: " + Physics2D.OverlapCircle(groundCheckLeft.position, groundRadius, whatIsGround));


        anim.SetBool("Ground", grounded);



        float move = CnInputManager.GetAxis("Horizontal");

        rigidBody2D.velocity = new Vector2(move * maxSpeed, rigidBody2D.velocity.y);

        anim.SetFloat("Speed", Mathf.Abs(move));
        anim.SetFloat("vSpeed", rigidBody2D.velocity.y);

        if (move > 0 && !facingRight)
        {
            Flip();
        }
        else if (move < 0 && facingRight)
        {
            Flip();
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        float h = CnInputManager.GetAxis("Horizontal") * speed;
        float v = CnInputManager.GetAxis("Vertical") * speed;

        _myBody.velocity = new Vector2(h, v);
    }
Ejemplo n.º 3
0
        void CmdShoot()
        {
            Vector2 shootVec = new Vector2(CnInputManager.GetAxis("Horizontal"), CnInputManager.GetAxis("Vertical"));
            float   angle    = Mathf.Atan2(shootVec.y, shootVec.x) * Mathf.Rad2Deg - 90f;

            switch (LocalPlayerType)
            {
            case Constant.FireElementType:
                this.GetComponent <FireElement> ().fire(this.transform.position, angle, shootVec.normalized);
                break;

            case Constant.ElectricElementType:
                this.GetComponent <ElectricElement> ().fire(this.transform.position, angle, shootVec.normalized);
                break;

            case Constant.IceElementType:
                this.GetComponent <IceElement> ().fire(this.transform.position, angle, shootVec.normalized);
                break;

            case Constant.DarkElementType:
                this.GetComponent <DarkElement> ().fire(this.transform.position, angle, shootVec.normalized);
                break;

            case Constant.StoneElementType:
                this.GetComponent <StoneElement> ().showShadow(this.transform.position, angle, shootVec.normalized);
                break;
            }
        }
    void FixedUpdate()
    {
        State = DarthState.stoping;


        CheckGround();

        if (Convert.ToBoolean(CnInputManager.GetAxis("Horizontal")))
        {
            Run();
        }
        if (isGrounded && CnInputManager.GetButtonDown("Jump"))
        {
            Jump();
        }
        if (CnInputManager.GetButtonDown("Attack"))
        {
            Shoot();
        }

        ////чтобы часто не стрелять
        //shotsTimeCounter -= Time.deltaTime;



        //фича высоко не прыгать
        if (gameObject.transform.position.y >= 5.500000F)
        {
            gameObject.transform.position = new Vector2(gameObject.transform.position.x, 5.500000F);
        }
    }
Ejemplo n.º 5
0
        private void Update()
        {
            var movementVector = new Vector3(CnInputManager.GetAxis("Horizontal"), 0f, CnInputManager.GetAxis("Vertical"));

            if (movementVector.sqrMagnitude < 0.00001f)
            {
                return;
            }

            // Clamping
            Vector3 closestDirectionVector = directionalVectors[0];
            float   closestDot             = Vector3.Dot(movementVector, closestDirectionVector);

            for (int i = 1; i < directionalVectors.Length; i++)
            {
                float dot = Vector3.Dot(movementVector, directionalVectors[i]);
                if (dot < closestDot)
                {
                    closestDirectionVector = directionalVectors[i];
                    closestDot             = dot;
                }
            }

            // closestDirectionVector is what we need
            var transformedDirection = _mainCameraTransform.InverseTransformDirection(closestDirectionVector);

            transformedDirection.y = 0f;
            transformedDirection.Normalize();

            transform.position += transformedDirection * Time.deltaTime;
        }
    public void Update()
    {
        // Just use CnInputManager. instead of Input. and you're good to go
        var     inputVector    = new Vector3(CnInputManager.GetAxis("Horizontal"), CnInputManager.GetAxis("Vertical"));
        Vector3 movementVector = Vector3.zero;

        // If we have some input
        _animator.SetFloat("Speed", 0.0f);
        if (inputVector.sqrMagnitude > 0.001f)
        {
            movementVector   = _mainCameraTransform.TransformDirection(inputVector);
            movementVector  *= MovementSpeed;
            movementVector.y = 0f;
            _animator.SetFloat("Speed", movementVector.sqrMagnitude * MovementSpeed);
            movementVector.Normalize();
            _transform.forward = Vector3.MoveTowards(movementVector, _transform.forward, Time.deltaTime);
        }

        if (transform.position.y > 0)
        {
            movementVector += Physics.gravity;
        }

        transform.position = Vector3.MoveTowards(transform.position, transform.position + movementVector, Time.deltaTime * MovementSpeed);
    }
Ejemplo n.º 7
0
    void FixedUpdate()
    {
        if (!this.movable)
        {
            return;
        }
        float h    = CnInputManager.GetAxis("Horizontal");
        float v    = CnInputManager.GetAxis("Vertical");
        var   dirc = new Vector3(h, v, 0);

        if (dirc.magnitude > 1)
        {
            dirc /= dirc.magnitude;
        }

        RotateToLookup(dirc);

        if (h != 0f || v != 0f)
        {
            myAnimator.SetBool("Moving", true);
            body.velocity = dirc * currentMoveSpeed;
        }
        else
        {
            myAnimator.SetBool("Moving", false);
            body.velocity = Vector3.zero;
        }
    }
Ejemplo n.º 8
0
    void Move()
    {
        // Vector3 rightMovement = right * moveSpeed * Time.deltaTime * Input.GetAxis("Horizontal");
        // Vector3 upMovement = forward * moveSpeed * Time.deltaTime * Input.GetAxis("Vertical");

        Vector3 rightMovement = right * moveSpeed * Time.deltaTime * CnInputManager.GetAxis("Horizontal");
        Vector3 upMovement    = forward * moveSpeed * Time.deltaTime * CnInputManager.GetAxis("Vertical");

        Vector3 heading = Vector3.Normalize(rightMovement + upMovement);


        transform.position += rightMovement;
        transform.position += upMovement;

        if (upMovement != new Vector3(0, 0, 0))
        {
            transform.forward = heading;
            anim.SetBool("isWalking", true);
        }
        else if (rightMovement != new Vector3(0, 0, 0))
        {
            transform.forward = heading;
            anim.SetBool("isWalking", true);
        }
        else
        {
            anim.SetBool("isWalking", false);
        }
    }
Ejemplo n.º 9
0
 void FixedUpdate()
 {
     input = new Vector3(Input.GetAxis("Horizontal"), 0.0f, Input.GetAxis("Vertical"));//or
     input = new Vector3(CnInputManager.GetAxis("Horizontal"), 0.0f, CnInputManager.GetAxis("Vertical"));
     //input = input.normalized;
     rb.AddForce(input * speed);
 }
Ejemplo n.º 10
0
    // Update is called once per frame
    void FixedUpdate()
    {
        float movement = CnInputManager.GetAxis("Horizontal");

        isOnGround = Physics2D.OverlapCircle(groundCheck.position, groundRadius, groundLayers);
        playerAnim.SetBool("Ground", isOnGround);

        playerAnim.SetFloat("Speed", Mathf.Abs(movement));

        // if the player is being knocked back, remove controls
        if (isKnockedBack)
        {
            return;
        }

        rigidBody.velocity = new Vector2(movement * maxSpeed, rigidBody.velocity.y);
        if (Mathf.Abs(movement) > 0 && !playerAudio.isPlaying && isOnGround)
        {
            playerAudio.PlayOneShot(runningAudioClip);
        }
        if ((movement > 0 && !facingRight) || (movement < 0 && facingRight))
        {
            Flip();
        }


        Vector3 pos = Camera.main.WorldToViewportPoint(transform.position);

        pos.x = Mathf.Min(pos.x, 0.97f);
        transform.position = Camera.main.ViewportToWorldPoint(pos);
    }
Ejemplo n.º 11
0
    void Update( )
    {
        state.grounded = isGrounded();

        if (state.grounded)
        {
            state.onAir = false;
        }
        else
        {
            state.onAir = true;
        }
        //// print(state.grounded);
        BetterJump();

        hrInput = (int)CnInputManager.GetAxis("Horizontal");


        ac.SetInteger("hrInput", hrInput);

        if (state.onAir)
        {
            ac.SetBool("Jump", true);
        }
        else if (state.onAir == false)
        {
            ac.SetBool("Jump", false);
        }

        if (hrInput == 0)
        {
            sp.flipX = false;
        }
    }
Ejemplo n.º 12
0
//FIXED_UPDATE
    void FixedUpdate()
    {
        float   horizontal = CnInputManager.GetAxis("Horizontal");
        Vector2 movement   = new Vector2(horizontal, 0);

        rb2d.AddForce(movement * speed);
    }
Ejemplo n.º 13
0
 void FixedUpdate()
 {
     //left right jump movement movement
     if (CnInputManager.GetAxis("Horizontal") > 0)
     {
         moveRight();
     }
     if (CnInputManager.GetAxis("Horizontal") < 0)
     {
         moveLeft();
     }
     if (CnInputManager.GetButtonDown("Jump"))
     {
         jump();
     }
     //stop
     if (playerRb.velocity.x == 0)
     {
         stopPlayer();
     }
     if (CnInputManager.GetButtonDown("Jump") && playerRb.velocity.x == 0)
     {
         sjump();
     }
 }
Ejemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        Vel_Y = RB.velocity.y;

        Move = CnInputManager.GetAxis("Horizontal") * Time.deltaTime * Move_Speed;
        transform.position = transform.position + new Vector3(Move, 0, 0);

        if (Move > 0 || (CnInputManager.GetButtonDown("Horizontal")))
        {
            transform.localEulerAngles = new Vector3(0, 0, 0);
            AnimGato.SetBool("isWalking", true);
        }
        else if (Move < 0 || (CnInputManager.GetButtonDown("Horizontal")))
        {
            transform.localEulerAngles = new Vector3(0, 180, 0);
            AnimGato.SetBool("isWalking", true);
        }
        else if (!Input.anyKey)
        {
            AnimGato.SetBool("isWalking", false);
        }

        if ((Input.GetButton("Jump") || CnInputManager.GetButtonDown("Jump")) && Grounded == true && Space_Down == false)
        {
            audio.clip = Salto;
            audio.Play();
            AnimGato.SetBool("Jump", true);
            RB.AddForce(0, Jump, 0);
            Space_Down = true;
        }

        if (Input.GetKey(KeyCode.Space) != true)
        {
            Space_Down = false;
        }

        if (RB.velocity.y < 0)
        {
            AnimGato.SetBool("Jump", false);
            AnimGato.SetBool("Falling", true);
        }

        if (Grounded == true)
        {
            AnimGato.SetBool("Falling", false);
        }

        if (transform.position.y < -4.9f)
        {
            audio.clip = Muerte;
            audio.Play();
            transform.position = new Vector3(-0.28f, 2.3f, 5);
            Destroy(GameObject.FindGameObjectWithTag("Pajaro"));
            if (Vidas != 0)
            {
                GameObject.Find("Vida" + Vidas).SetActive(false);
                Vidas--;
            }
        }
    }
Ejemplo n.º 15
0
    void Move()
    {
        if (IsCanControl)
        {
            var     inputVector    = new Vector2(CnInputManager.GetAxis("Horizontal"), CnInputManager.GetAxis("Vertical"));
            Vector3 movementVector = inputVector;

            isWillMove = inputVector != Vector2.zero ? true : false;

            if (isWillMove)
            {
                float angle = RotateAngleWithCameraView(inputVector); //Calculate Rotation Angle
                transform.rotation = Quaternion.Euler(0, angle, 0);   //Set Rotation Angle

                movementVector += Physics.gravity;

                Vector3 movePosition = movementVector * Time.deltaTime * playerController.AttributesController.speed;
                movePosition.y = 0;
                transform.Translate(movePosition);
                inputMoveSpeed = inputVector.magnitude;
            }
            else
            {
                inputMoveSpeed = Vector3.zero.magnitude;
            }
        }
        else
        {
            inputMoveSpeed = Vector3.zero.magnitude;
        }
    }
Ejemplo n.º 16
0
    void Update()
    {
        if (CanMove)
        {
            if (Input.GetKeyDown(KeyCode.Space) && movementDirection != Vector2.zero && !makeingRoll)
            {
                makeingRoll   = true;
                rollStartTime = Time.timeSinceLevelLoad;
                velocity     *= rollVelocityMultiplier;
            }

            if (gameObject.activeSelf && CanMove && !makeingRoll)
            {
                movementDirection.x = CnInputManager.GetAxis("Horizontal");
                movementDirection.y = CnInputManager.GetAxis("Vertical");
            }
            else
            {
                if (makeingRoll)
                {
                    if (rollStartTime + rollTime < Time.timeSinceLevelLoad)
                    {
                        velocity   /= rollVelocityMultiplier;
                        makeingRoll = false;
                        rb.velocity = Vector2.zero;
                    }
                }
            }
        }
    }
Ejemplo n.º 17
0
 void Update()
 {
     if (controller == 1)
     {
         if (CnInputManager.GetAxis("Horizontal") > 0 && Container.transform.position.x < 186)
         {                                                                //for right side movement
             movement = CnInputManager.GetAxis("Horizontal") * moveSpeed; //CnInput is used for Cn Control buttons.[left n right arrow here]
             Container.transform.position = new Vector2(Container.transform.position.x + movement, Container.transform.position.y);
         }
         else if (CnInputManager.GetAxis("Horizontal") < 0 && Container.transform.position.x > 6)
         {             //for left side movement
             movement = CnInputManager.GetAxis("Horizontal") * moveSpeed;
             Container.transform.position = new Vector2(Container.transform.position.x + movement, Container.transform.position.y);
         }
     }
     if (controller == 2)
     {
         if (Input.acceleration.x > 0 && Container.transform.position.x < 186) //for right side movement
         {
             movement = Input.acceleration.x * 17;                             //used with sensor of mobile
             Container.transform.position = new Vector2(Container.transform.position.x + movement, Container.transform.position.y);
         }
         else if (Input.acceleration.x < 0 && Container.transform.position.x > 6)            //for left side movement
         {
             movement = Input.acceleration.x * 17;
             Container.transform.position = new Vector2(Container.transform.position.x + movement, Container.transform.position.y);
         }
     }
 }
Ejemplo n.º 18
0
    private void Move()
    {
        var inputVector = new Vector3(CnInputManager.GetAxis("Horizontal"), 0,
                                      CnInputManager.GetAxis("Vertical"));

        if (inputVector.sqrMagnitude > 0.01f) // 움직이면
        {
            tr.Rotate(Vector3.up * inputVector.x * rotSpeed * Time.deltaTime);

            //float index;

            //index = (inputVector.x > 0.35) ? 17 - inputVector.z : (inputVector.x < -0.35) ? 17 + inputVector.z : 18;

            pv.RPC("SetAni", PhotonTargets.All, 18);

            //tr.Translate(Vector3.forward * inputVector.z * speed * Time.deltaTime);

            rigid.velocity = inputVector * speed;

            rigid.position = new Vector3
                                 (Mathf.Clamp(rigid.position.x, -24.5f, 24.5f),
                                 tr.position.y,
                                 Mathf.Clamp(rigid.position.z, -24.5f, 24.5f));
        }

        if (inputVector.sqrMagnitude == 0.0f)
        {
            pv.RPC("SetAni", PhotonTargets.All, 1);
            rigid.velocity = Vector3.zero;
        }

        //tr.Translate(Vector3.down * 9.8f * Time.deltaTime);
    }
Ejemplo n.º 19
0
 // Update is called once per frame
 void FixedUpdate()
 {
     if (GameActive)
     {
         Vector3 moveInput = new Vector3(CnInputManager.GetAxis("Horizontal"), 0, 0);
         if (moveInput.magnitude > 0)
         {
             targetRotation = Quaternion.LookRotation(moveInput);
         }
         else
         {
             targetRotation = Quaternion.LookRotation(Vector3.forward);
         }
         Vector3 moveVelocity = moveInput.normalized * MoveSpeed;
         rigidBody.MovePosition(rigidBody.position + moveVelocity * Time.fixedDeltaTime);
         Player.rotation = Quaternion.Lerp(Player.rotation, targetRotation, Smooth * Time.fixedDeltaTime);
         animator.SetFloat("Speed", moveVelocity.magnitude / MoveSpeed);
     }
     else
     {
         Vector3 moveInput    = new Vector3(0, 0, 0);
         Vector3 moveVelocity = moveInput.normalized * MoveSpeed;
         animator.SetFloat("Speed", moveVelocity.magnitude / MoveSpeed);
     }
 }
Ejemplo n.º 20
0
    // Update is called once per frame
    void Update()
    {
        shoot_button = CnInputManager.GetButton("Jump");
        moving.x     = moving.y = 0;

        Vector2 movement = new Vector2(CnInputManager.GetAxis("Horizontal"), CnInputManager.GetAxis("Vertical"));

        if (movement.x > 0)
        {
            moving.x             = 1;
            transform.localScale = new Vector3(1, 1, 1);
        }
        else if (movement.x < 0)
        {
            moving.x             = -1;
            transform.localScale = new Vector3(-1, 1, 1);
        }

        // for jump



        if (movement.y > 0)
        {
            moving.y = 1;
        }
        else if (movement.y < 0)
        {
            moving.y = -1;
        }
    }
Ejemplo n.º 21
0
    // This is called once per frame
    void Update()
    {
        // check if flying
        CheckFlying();

        // check if falling too fast
        //CheckVelo();

        // keep the player in bounds
        CheckInBounds();

        // Joystick input handling - need to move this to a seperate function "Move()"
        float h = CnInputManager.GetAxis("Horizontal");

        Move(h, true);
        float v = CnInputManager.GetAxis("Vertical");

        Move(v, false);
        if (h == 0)
        {
            AddGravity();
            lastMoveHoriz = 0;
            lastMoveVert  = 0;
        }
    }
Ejemplo n.º 22
0
    private void FixedUpdate()
    {
        startTimer -= Time.deltaTime;

        if (startTimer <= 0 && speed > 0.5f)
        {
            var newVelocity = rb.velocity;

            newVelocity.z = -25.0f; //30
            rb.velocity   = newVelocity;
            //rb.AddRelativeForce(Vector3.forward * -10);
            newVelocity.x = -15.0f * CnInputManager.GetAxis("Horizontal");
            //rb.AddRelativeForce(-0.5f * CnInputManager.GetAxis("Horizontal"), 0, 0, ForceMode.VelocityChange);
            //if (transform.position.x >= -5f && transform.position.x <= 5f)
            //{
            if (rb.velocity.y != 0)
            {
                SavedVelocity.y = newVelocity.y;
            }
            newVelocity.y = SavedVelocity.y;
            rb.velocity   = newVelocity;


            Physics.gravity = new Vector3(0, -25, 0);
            if (Time.timeScale < 0.3f || GameController.Instance.isPaused)
            {
                if (rb.velocity.y != 0)
                {
                    SavedVelocity.y = rb.velocity.y / 1.25f;
                }
                Physics.gravity = new Vector3(0, 0, 0);
                rb.velocity     = new Vector3(0, 0, 0);
            }
        }
    }
Ejemplo n.º 23
0
    void FixedUpdate()
    {
//		float moveHorizontal = Input.GetAxis ("Horizontal");
//		float moveVertical = Input.GetAxis ("Vertical");

//		Vector3 a = Input.acceleration;

//		Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

//		Vector3 movement = new Vector3 (a.x, 0.0f, a.y);
//		dir = t.GetComponent<move>().getDir();

//		Vector3 movement = new Vector3 (dir.x, 0.0f, dir.y);
        Vector3 movement = new Vector3(CnInputManager.GetAxis("Horizontal"), 0f, CnInputManager.GetAxis("Vertical"));

        boundary.xMin = Camera.main.ViewportToWorldPoint(new Vector3(0, 1, 9)).x;
        boundary.xMax = Camera.main.ViewportToWorldPoint(new Vector3(1, 1, 9)).x;
        boundary.zMax = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.65f, 9.0f)).z;
        boundary.zMin = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.0f, 9.0f)).z;

        GetComponent <Rigidbody> ().velocity = movement * speed;

        GetComponent <Rigidbody> ().position = new Vector3(
            Mathf.Clamp(GetComponent <Rigidbody> ().position.x, boundary.xMin, boundary.xMax),
            0.0f,
            Mathf.Clamp(GetComponent <Rigidbody> ().position.z, boundary.zMin, boundary.zMax)
            );

        GetComponent <Rigidbody> ().rotation = Quaternion.Euler(0.0f, 0.0f, GetComponent <Rigidbody> ().velocity.x * -tilt);
    }
Ejemplo n.º 24
0
    void Update()
    {
        if (UnitZ.playerManager.PlayingCharacter != null)
        {
            SetVisible(true);
            FPSController fpsControl = UnitZ.playerManager.PlayingCharacter.GetComponent <FPSController>();
            if (fpsControl)
            {
                MouseLock.IsMobileControl = true;
                fpsControl.MoveCommand(new Vector3(CnInputManager.GetAxis("Horizontal"), 0, CnInputManager.GetAxis("Vertical")), CnInputManager.GetButton("Jump"));
                fpsControl.Aim(new Vector2(CnInputManager.GetAxis("Touch X") * AimSensitivity, CnInputManager.GetAxis("Touch Y") * AimSensitivity));
                fpsControl.Trigger1(CnInputManager.GetButton("Touch Fire1"));

                /*fpsControl.Trigger2(CnInputManager.GetButtonDown("Fire2"));
                 *
                 * if (CnInputManager.GetButtonDown("Fire3"))
                 * {
                 *  fpsControl.OutVehicle();
                 *  fpsControl.Interactive();
                 * }
                 *
                 * if (CnInputManager.GetButtonDown("Submit"))
                 * {
                 *  fpsControl.Reload();
                 * }*/

                fpsControl.Checking();
            }
        }
        else
        {
            SetVisible(false);
        }
    }
Ejemplo n.º 25
0
 public void Update()
 {
     if (vivo)
     {
         var     inputVector    = new Vector2(CnInputManager.GetAxis("Horizontal"), CnInputManager.GetAxis("Vertical"));
         Vector3 movementVector = Vector2.zero;
         if (inputVector.sqrMagnitude > 0.001f)
         {
             movementVector = _mainCameraTransform.TransformDirection(inputVector);
             if (movementVector.x == 1)
             {
                 _transform.position = transform.position - Vector3.left * MovementSpeed;
                 _transform.rotation = Quaternion.Euler(0, 0, 270);
             }
             else if (movementVector.x == -1)
             {
                 _transform.position = transform.position - Vector3.right * MovementSpeed;
                 _transform.rotation = Quaternion.Euler(0, 0, 90);
             }
             else if (movementVector.y == 1)
             {
                 _transform.position = transform.position - Vector3.down * MovementSpeed;
                 _transform.rotation = Quaternion.Euler(0, 0, 0);
             }
             else if (movementVector.y == -1)
             {
                 _transform.position = transform.position - Vector3.up * MovementSpeed;
                 _transform.rotation = Quaternion.Euler(0, 0, 180);
             }
         }
     }
 }
    protected override void UpdateVelocity()
    {
        if (GetComponent <PlayerData> ().pIsDead)
        {
            return;
        }

        var desiredVelocity = new Vector3(CnInputManager.GetAxis(horizontalAxisName), CnInputManager.GetAxis(verticalAxisName), 0.0f);

        if (desiredVelocity.magnitude < joystickThreshold)
        {
            pIsControlling = false;
            _currentSpeed  = 0;
        }
        else
        {
            if (!pIsControlling)
            {
                _currentSpeed = _initialSpeed;
                _velocity     = desiredVelocity;
            }
            else
            {
                var steeringVector = steering.GetSteeringByTwoVelocity(_velocity, desiredVelocity);
                _velocity += steeringVector;
            }
            pIsControlling = true;
        }

        base.UpdateVelocity();
    }
Ejemplo n.º 27
0
    public float GetAxis(myKeyCode keyCode)
    {
        //返回控制移动的左摇杆
        switch (keyCode)
        {
        case myKeyCode.Horizontal:
            if (CnInputManager.GetAxis("Horizontal") != 0)
            {
                return(CnInputManager.GetAxis("Horizontal"));
            }
            if (Input.GetAxis("Horizontal") != 0)
            {
                return(Input.GetAxis("Horizontal"));
            }
            break;

        case myKeyCode.Vertical:
            if (CnInputManager.GetAxis("Vertical") != 0)
            {
                return(CnInputManager.GetAxis("Vertical"));
            }
            if (Input.GetAxis("Vertical") != 0)
            {
                return(Input.GetAxis("Vertical"));
            }
            break;
        }
        return(0);
    }
Ejemplo n.º 28
0
    void Input()
    {
        if (!isLocalPlayer)
        {
            return;
        }
        if (CanMove == true)
        {
            //get horizontal and vertical input from controller
            horizontalMovement = CnInputManager.GetAxis("Horizontal");
            verticalMovement   = CnInputManager.GetAxis("Vertical");
            if (movement != Vector3.zero)
            {
                targetRotation = Quaternion.LookRotation(movement, Vector3.up);
            }
            else
            {
                targetRotation = transform.rotation;
            }
            CmdMove(horizontalMovement, verticalMovement, targetRotation);
        }

        if (CnInputManager.GetButton("Attack"))
        {
            //attacking variable isn't really used for anything, but attack doesn't seem to synchronize unless they have at least one parameter.
            attacking = true;
            CmdAttack(attacking);
        }
    }
Ejemplo n.º 29
0
 // Update is called once per frame
 void Update()
 {
     if (!isLocalPlayer || skill.isCooldown())
     {
         return;
     }
     if (CnInputManager.GetButtonDown(simpleButtonName))
     {
         skill.ButtonDown();
     }
     if (CnInputManager.GetButtonUp(simpleButtonName) && !cancelSkill)
     {
         skill.ButtonUp();
     }
     if (CnInputManager.GetButtonUp(simpleButtonName) && cancelSkill)
     {
         skill.ButtonCancel();
     }
     if (!isPressButton && CnInputManager.GetButton(simpleButtonName))
     {
         skill.ButtonDirection(CnInputManager.GetAxis(verticalButtonName), CnInputManager.GetAxis(horizontalButtonName));
     }
     if (CnInputManager.GetButtonDown("CancelSkill"))
     {
         cancelSkill = true;
     }
     if (CnInputManager.GetButtonUp("CancelSkill"))
     {
         cancelSkill = false;
     }
 }
Ejemplo n.º 30
0
    void Update()
    {
        float dirHor = CnInputManager.GetAxis("Horizontal");
        float dirVer = CnInputManager.GetAxis("Vertical");


        //Vector2 moveVect = new Vector2(dirHor, dirVer) * speed;
        Vector3 rotVect = new Vector3(dirHor, dirVer, 0.0f);



        if (dirHor != 0 || dirVer != 0)
        {
            angle = Mathf.Atan2(dirVer, dirHor) * Mathf.Rad2Deg;
            transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
            //transform.RotateAround(PlayerCollider.bounds.center, Vector3.forward, angle);
            lastAngle = angle;
            transform.Translate(rotVect * speed * Time.deltaTime, Space.World);
            lastVect = new Vector3(dirHor, dirVer, 0.0f);
        }
        else
        {
            transform.rotation = Quaternion.AngleAxis(lastAngle, Vector3.forward);
            transform.Translate(lastVect * speed * Time.deltaTime, Space.World);
        }
    }