move() public method

attempts to move the character to position + deltaMovement. Any colliders in the way will cause the movement to stop when run into.
public move ( Vector3 deltaMovement ) : void
deltaMovement Vector3 Delta movement.
return void
コード例 #1
0
ファイル: Villager.cs プロジェクト: sky-coding/ludum43
    void Update()
    {
        if (isDead)
        {
            return;
        }

        if (characterController.isGrounded)
        {
            _velocity.y = 0;
        }

        var smoothedMovementFactor = characterController.isGrounded ? groundDamping : inAirDamping;

        _velocity.x  = Mathf.Lerp(_velocity.x, _normalizedHorizontalSpeed * runSpeed, Time.deltaTime * smoothedMovementFactor);
        _velocity.y += gravity * Time.deltaTime;
        characterController.move(_velocity * Time.deltaTime);
        _velocity = characterController.velocity;

        var levelBoundsMin = levelBoundsPolygonCollider2D.bounds.min;
        var levelBoundsMax = levelBoundsPolygonCollider2D.bounds.max;

        if (transform.position.x < levelBoundsMin.x || transform.position.x > levelBoundsMax.x ||
            transform.position.y < levelBoundsMin.y || transform.position.y > levelBoundsMax.y)
        {
            Destroy(gameObject);
        }
    }
コード例 #2
0
    // the Update loop contains a very simple example of moving the character around and controlling the animation
    void Update()
    {
        if (_controller.isGrounded)
        {
            _velocity.y = 0;
        }

        //normalizedHorizontalSpeed = 0;

        // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control
        var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping;         // how fast do we change direction?

        _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * runSpeed, Time.deltaTime * smoothedMovementFactor);

        // apply gravity before moving
        _velocity.y += gravity * Time.deltaTime;

        // if holding down bump up our movement amount and turn off one way platform detection for a frame.
        // this lets us jump down through one way platforms
        if (_controller.isGrounded && Input.GetKey(KeyCode.DownArrow))
        {
            _velocity.y *= 3f;
            _controller.ignoreOneWayPlatformsThisFrame = true;
        }

        _controller.move(_velocity * Time.deltaTime);

        // grab our current _velocity to use as a base for all calculations
        _velocity = _controller.velocity;
    }
コード例 #3
0
    void Update()
    {
        velocity = controller.velocity;

        if (controller.isGrounded)
        {
            velocity.y = 0;
        }


        if (facingRight && controller.isGrounded)
        {
            normalizedHorizontalSpeed = 1;
        }
        else if (!facingRight && controller.isGrounded)
        {
            normalizedHorizontalSpeed = -1;
        }
        else
        {
            normalizedHorizontalSpeed = 0;
        }

        velocity.x  = Mathf.Lerp(velocity.x, normalizedHorizontalSpeed * walkSpeed, Time.deltaTime * groundDamping);
        velocity.y += gravity * Time.deltaTime;
        controller.move(velocity * Time.deltaTime);
    }
コード例 #4
0
    private void Update()
    {
        Fix dt = (Fix)Time.deltaTime;

        if (Input.GetKey(KeyCode.A))
        {
            velo.x = -movementSpeed * dt;
        }
        else if (Input.GetKey(KeyCode.D))
        {
            velo.x = movementSpeed * dt;
        }
        else
        {
            velo.x = 0;
        }

        if (Input.GetKey(KeyCode.W))
        {
            velo.y = movementSpeed * dt;
        }
        else if (Input.GetKey(KeyCode.S))
        {
            velo.y = -movementSpeed * dt;
        }
        else
        {
            velo.y = 0;
        }

        charController.move(velo);
    }
コード例 #5
0
    protected virtual void Update()
    {
        // Gravity and Movement
        // if (!stopGravity)
        // {
        //     moveDirection.y -= gravity * Time.deltaTime;
        //     // moving left or right (or jump or fall)
        //     cc2d.move(moveDirection * Time.deltaTime);
        // }


        //if (!stopGravity || isClimbing) // order??????
        if (!isClimbing) // order??????
        {
            moveDirection.y -= gravity * Time.deltaTime;
        }
        cc2d.move(moveDirection * Time.deltaTime);

        // report what is around us
        flags = cc2d.collisionState;

        /// Check if we are on the ground
        isGrounded = flags.below;
        //isRight = flags.right;
        //isLeft = flags.left;

        /// Check if we hit our head
        // if (flags.above)
        // {
        //     moveDirection.y -= gravity * Time.deltaTime;
        //     moveDirection.x = 0;
        // }
    }
コード例 #6
0
 /// <summary>
 /// _sets the current velocity after modifications.
 /// </summary>
 /// <param name="aVelocity_vector3">A velocity_vector3.</param>
 protected void _setCurrentVelocityAfterModifications(Vector3 aVelocity_vector3)
 {
     if (_characterController2D.enabled)
     {
         _characterController2D.move(aVelocity_vector3 * Time.deltaTime);
     }
 }
コード例 #7
0
        public override void DoState(BasicEnemy enemy, List <SteeringEffect> steerings, CharacterController2D controller, List <Effect> effects)
        {
            var currentSteering = Vector2.zero;
            var totalWeight     = 0.0f;

            foreach (SteeringEffect s in steerings)
            {
                var curWeight = s.GetWeight(enemy, steerings.Count);
                if (s == this)
                {
                    curWeight *= 2;
                }
                currentSteering += s.GetSteering(enemy, currentSteering) * curWeight;
                totalWeight     += curWeight;
            }

            currentSteering /= totalWeight;

            enemy.velocity = currentSteering * Time.deltaTime;

            enemy.ProbablisticState();

            if (player == null)
            {
                enemy.ChangeToDefaultState();
            }

            controller.move(enemy.velocity);
        }
コード例 #8
0
    // the Update loop contains a very simple example of moving the character around and controlling the animation
    void Update()
    {
        if (player.GetActionState() != PlayerActionState.DEAD &&
            pauseState.instance.GetPauseState() != PAUSESTATE.PAUSED)
        {
            GetInput();

            CheckWall();

            // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control
            var smoothedMovementFactor = _controller.isGrounded ? player.groundDamping : player.inAirDamping; // how fast do we change direction?
            _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * player.moveSpeed, Time.deltaTime * smoothedMovementFactor);

            _velocity.y += player.gravity * Time.deltaTime;

            _controller.move(_velocity * Time.deltaTime);

            if (_controller._isGoingUpSlope && normalizedHorizontalSpeed > 0)
            {
                this.transform.position = new Vector3(transform.position.x, transform.position.y + _controller.skinWidth, transform.position.z);
            }

            // grab our current _velocity to use as a base for all calculations
            _velocity = _controller.velocity;

            Debug.Log("Grounded: " + _controller.isGrounded);

            Vector3 screenPos = Camera.main.WorldToScreenPoint(transform.position);

            screenPos.x = Mathf.Clamp(screenPos.x, 0f + clampOffset, Screen.width - clampOffset);
            screenPos.y = Mathf.Clamp(screenPos.y, 0f + clampOffset, Screen.height - clampOffset);

            transform.position = Camera.main.ScreenToWorldPoint(screenPos);
        }
    }
コード例 #9
0
        public override void DoState(BasicEnemy enemy, List <SteeringEffect> steerings, CharacterController2D controller, List <Effect> effects)
        {
            var currentSteering = Vector2.zero;
            var totalWeight     = 0.0f;

            currentTime += Time.deltaTime;

            foreach (SteeringEffect s in steerings)
            {
                if (s.type == "distance")
                {
                    continue;
                }

                currentSteering += s.GetSteering(enemy, currentSteering) * s.GetWeight(enemy, steerings.Count);
                totalWeight     += s.GetWeight(enemy, steerings.Count);
            }

            currentSteering /= totalWeight;

            enemy.velocity = currentSteering * Time.deltaTime;

            if (currentTime > attackInTime)
            {
                enemy.ProbablisticState();
            }

            controller.move(enemy.velocity);
        }
コード例 #10
0
    private void Update()
    {
        if (controller2D.isGrounded)
        {
            velocity.y = 0;
        }

        if (normalizedHorizontalSpeed == 1)
        {
            if (transform.localScale.x < 0f)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }
        }
        else if (normalizedHorizontalSpeed == -1)
        {
            if (transform.localScale.x > 0f)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }
        }

        velocity.x  = Mathf.Lerp(velocity.x, normalizedHorizontalSpeed * moveSpeed, Time.deltaTime * groundDamping);
        velocity.y += gravity * Time.deltaTime;

        controller2D.move(velocity * Time.deltaTime);
        velocity = controller2D.velocity;
    }
コード例 #11
0
    void Update()
    {
        if (playerControl)
        {
            Vector3 velocity = PlayerInput();
            _controller.move(velocity * Time.deltaTime);
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            pause = !pause;
            if (pause)
            {
                Time.timeScale = 0;
                pausePanel.SetActive(true);
                playerControl = false;
                _animator.setAnimation("Idle");
            }
            else
            {
                Time.timeScale = 1;
                pausePanel.SetActive(false);
                playerControl = true;
            }
        }
    }
コード例 #12
0
    void defaultMove(float walkSpeed, float jumpHeight)
    {
        Vector3 velocity = _controller.velocity;

        velocity.x = 0;

        velocity.x = walkSpeed * enemyDirection;

        velocity.y += gravity * Time.deltaTime;


        //PATROLLING MOVEMENT
        if (enemyDirection == -1 && this.transform.position.x <= spot1X)
        {
            enemyState = 0;
            isWaiting  = true;
            Invoke("idleWait", waitTime);
            Invoke("flipChar", waitTime);
            enemyDirection *= -1;
        }
        else if (enemyDirection == 1 && this.transform.position.x >= spot2X)
        {
            enemyState = 0;
            isWaiting  = true;
            Invoke("idleWait", waitTime);
            Invoke("flipChar", waitTime);
            enemyDirection *= -1;
        }

        _controller.move(velocity * Time.deltaTime);
    }
コード例 #13
0
    // Update is called once per frame
    void Update()
    {
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");

        Vector3 direction = new Vector3(h, v, 0f);

        if (direction != Vector3.zero)
        {
            lastDirection = direction;
        }

        Vector3 directionNormalized     = direction.normalized;
        Vector3 lastDirectionNormalized = lastDirection.normalized;

        float angle = Mathf.Atan2(lastDirection.y, lastDirection.x) * Mathf.Rad2Deg;

        transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

        dashCooldownTimer += Time.deltaTime;

        switch (state)
        {
        case PlayerState.NORMAL:
            _controller.move(directionNormalized * speed * Time.deltaTime);
            // rigid.MovePosition(this.transform.position + directionNormalized * speed * Time.deltaTime);

            if (Input.GetButtonDown("Jump") && dashCooldownTimer > dashCooldown)
            {
                state = PlayerState.DASH;
            }
            break;

        case PlayerState.DASH:
            _controller.move(lastDirectionNormalized * dashSpeed * Time.deltaTime);
            // rigid.MovePosition(this.transform.position + lastDirectionNormalized * dashSpeed * Time.deltaTime);

            dashTimer += Time.deltaTime;
            if (dashTimer > dashLength)
            {
                dashTimer         = 0.0f;
                state             = PlayerState.NORMAL;
                dashCooldownTimer = 0.0f;
            }
            break;
        }
    }
コード例 #14
0
    protected void ApplyMovement()
    {
        float smoothedMovement = IsGrounded ? groundDamping : airDamping;

        velocity.x = Mathf.Lerp(velocity.x,
                                horizontalMovement * moveSpeed,
                                smoothedMovement * Time.deltaTime);
        velocity.y += gravity * Time.deltaTime;
        controller.move(velocity * Time.deltaTime);
        velocity = controller.velocity;

        if (IsGrounded)
        {
            velocity.y           = 0f;
            lastGroundedPosition = transform.position;
        }
    }
コード例 #15
0
ファイル: Doll.cs プロジェクト: Thiiamas/MindMess
 private void Update()
 {
     if (!characterController.isGrounded)
     {
         velocity.y += Physics2D.gravity.y * Time.deltaTime;
     }
     characterController.move(velocity * Time.deltaTime);
 }
コード例 #16
0
    // the Update loop contains a very simple example of moving the character around and controlling the animation
    void Update()
    {
        if (_controller.isGrounded)
        {
            _velocity.y = 0;
        }


        _velocity.y += gravity * Time.deltaTime;

        if (transform.childCount > 1 && _controller.isGrounded)
        {
            EdgeDetection();
        }

        CheckForObstacle();

        // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control
        if (!dead)
        {
            var   smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping;           // how fast do we change direction?
            float speed = runSpeed;
            _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * speed, Time.deltaTime * smoothedMovementFactor);
        }

        if (ducked)
        {
            _velocity.x = 0;
        }

        // if holding down bump up our movement amount and turn off one way platform detection for a frame.
        // this lets us jump down through one way platforms
        // if( _controller.isGrounded && Input.GetKey( KeyCode.DownArrow ) )
        // {
        //  _velocity.y *= 3f;
        //  _controller.ignoreOneWayPlatformsThisFrame = true;
        // }

        // UpdateSpriteOrientation();
        // UpdateAnimation();

        _controller.move(_velocity * Time.deltaTime);

        // grab our current _velocity to use as a base for all calculations
        _velocity = _controller.velocity;
    }
コード例 #17
0
ファイル: TurtleController.cs プロジェクト: PatoDL/Garomo
    void onTriggerEnterEvent(Collider2D col)
    {
        if (col.tag == "Attack")
        {
            if (life <= 1)
            {
                GetComponent <SpriteRenderer>().sprite = deadTurtle;
                _animator.enabled = false;
                _controller.boxCollider.enabled = false;
                _controller.rigidBody2D.Sleep();
                falling     = true;
                fallingTime = fallingMaxTime;
                if (GameManager.Instance.soundOn)
                {
                    AkSoundEngine.PostEvent("Turtle_Death", gameObject);
                }
            }
            else
            {
                life -= 1;
                _animator.SetTrigger("Damage");
                wasDamaged = true;
                recoilTime = recoilTimeMax;

                if ((col.transform.position.x > transform.position.x && normalizedHorizontalSpeed == -1) ||
                    (col.transform.position.x < transform.position.x && normalizedHorizontalSpeed == 1))
                {
                    normalizedHorizontalSpeed = -normalizedHorizontalSpeed;
                }
            }
        }
        else if (col.tag == "Redirectioner")
        {
            normalizedHorizontalSpeed = -normalizedHorizontalSpeed;
            if (wasDamaged)
            {
                _velocity = Vector3.zero;
                _controller.move(_velocity * Time.deltaTime);
            }
        }

        if (col.tag == "LimitTrigger")
        {
            gameObject.SetActive(false);
        }
    }
コード例 #18
0
ファイル: Enemy.cs プロジェクト: Thiiamas/MindMess
    public IEnumerator KnockBack(Vector3 direction, Vector2 force)
    {
        isKnockbacked = true;
        velocity      = direction * force;
        characterController.move(velocity * Time.deltaTime);

        while (velocity.x > .1f || velocity.x < -.1f)
        {
            velocity.x = Mathf.MoveTowards(velocity.x, 0, knockBackDeceleration * Time.deltaTime);
            characterController.move(velocity * Time.deltaTime);
            yield return(new WaitForEndOfFrame());
        }

        isKnockbacked = false;

        //StartCoroutine(Stun());
    }
コード例 #19
0
    void Update()
    {
        //Grabs current velocity of player
        var velocity = _controller.velocity;

        //Debug.Log ("X Velocity: " + _controller.velocity.x);
        //Debug.Log ("Y Velocity: " + _controller.velocity.y);

        if (_controller.isGrounded)
        {
            velocity.y = 0;
        }

        //Horizontal Input
        if (Input.GetKey(Right))
        {
            velocity.x = runSpeed;
            //goRight();
        }
        else if (Input.GetKey(Left))
        {
            velocity.x = -runSpeed;
            //goLeft();
        }
        if (_controller.isGrounded)
        {
            if (velocity.x < 0.001 && velocity.x > -0.001)
            {
                velocity.x = 0;
            }
            else
            {
                velocity.x *= decaySpeed;
            }
        }
        else
        {
            if (velocity.x < 0.001 && velocity.x > -0.001)
            {
                velocity.x = 0;
            }
            else
            {
                velocity.x *= decaySpeed;
            }
        }


        if (Input.GetKeyDown(Jump) && _controller.isGrounded)
        {
            var targetJumpHeight = jumpHeight;
            velocity.y = Mathf.Sqrt(2f * targetJumpHeight * -gravity);
        }

        velocity.y += gravity * Time.deltaTime;

        _controller.move(velocity * Time.deltaTime);
    }
コード例 #20
0
    // the Update loop contains a very simple example of moving the character around and controlling the animation
    void Update()
    {
        normalizedHorizontalSpeed = Input.GetAxisRaw(horizontalAxis);
        normalizedVerticalSpeed   = Input.GetAxisRaw(verticalAxis);

        if (Input.GetKey(KeyCode.LeftArrow))
        {
//			normalizedHorizontalSpeed = 1;
            if (transform.localScale.x < 0f)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }

//			_animator.Play( Animator.StringToHash( moveAnimation ) );
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
//			normalizedHorizontalSpeed = -1;
            if (transform.localScale.x > 0f)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }

//			_animator.Play( Animator.StringToHash( moveAnimation ) );
        }
        else
        {
//			normalizedHorizontalSpeed = 0;

//			_animator.Play( Animator.StringToHash( idleAnimation ) );
        }


        normalizedHorizontalSpeed = Input.GetAxisRaw(horizontalAxis);
        normalizedVerticalSpeed   = Input.GetAxisRaw(verticalAxis);

        // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control
        _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * runSpeed, Time.deltaTime * groundDamping);

        _velocity.y = Mathf.Lerp(_velocity.y, normalizedVerticalSpeed * runSpeed, Time.deltaTime * groundDamping);

        if (normalizedHorizontalSpeed != 0 || normalizedVerticalSpeed != 0)
        {
            //			heading = Mathf.Atan2 (normalizedVerticalSpeed, normalizedHorizontalSpeed);
            //			qTo = Quaternion.Euler (0f, 0f, (heading * Mathf.Rad2Deg) + 90);
            //			transform.localRotation = Quaternion.RotateTowards (transform.localRotation, qTo, rotationSpeed * Time.deltaTime);
            _animator.Play(Animator.StringToHash(moveAnimation));
        }
        else
        {
            _animator.Play(Animator.StringToHash(idleAnimation));
        }

        _controller.move(_velocity * Time.deltaTime);

        // grab our current _velocity to use as a base for all calculations
        _velocity = _controller.velocity;
    }
コード例 #21
0
    private void OnTriggerStay2D(Collider2D other)
    {
        Vector2   translate;
        Transform opponent = other.transform;

        translate = transform.position - opponent.position;
        translate.Normalize();
        parent.move(translate * strength);
    }
コード例 #22
0
 void onControllerCollider(RaycastHit2D hit)
 {
     if (hit.collider == _collider && _controller.collisionState.below && !_controller.collisionState.above)
     {
         _controller.move(new Vector3(_controller.velocity.x, 17f, 0f) * Time.deltaTime);
         StartCoroutine(Compress());
         // _controller.velocity.y = 5f;
     }
 }
コード例 #23
0
    // the Update loop contains a very simple example of moving the character around and controlling the animation
    void Update()
    {
        if (_controller.isGrounded)
        {
            _velocity.y = 0;
        }

        if (Input.GetKey(KeyCode.RightArrow))
        {
            normalizedHorizontalSpeed = 1;
            if (transform.localScale.x < 0f)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }
        }
        else if (Input.GetKey(KeyCode.LeftArrow))
        {
            normalizedHorizontalSpeed = -1;
            if (transform.localScale.x > 0f)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }
        }
        else
        {
            normalizedHorizontalSpeed = 0;
        }


        // we can only jump whilst grounded
        if (_controller.isGrounded && Input.GetKeyDown(KeyCode.UpArrow))
        {
            _velocity.y = Mathf.Sqrt(2f * jumpHeight * -gravity);
        }


        // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control
        var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping; // how fast do we change direction?

        _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * runSpeed, Time.deltaTime * smoothedMovementFactor);

        // apply gravity before moving
        _velocity.y += gravity * Time.deltaTime;

        // if holding down bump up our movement amount and turn off one way platform detection for a frame.
        // this lets us jump down through one way platforms
        if (_controller.isGrounded && Input.GetKey(KeyCode.DownArrow))
        {
            _velocity.y *= 3f;
            _controller.ignoreOneWayPlatformsThisFrame = true;
        }

        _controller.move(_velocity * Time.deltaTime);

        // grab our current _velocity to use as a base for all calculations
        _velocity = _controller.velocity;
    }
コード例 #24
0
    IEnumerator DiveKick()
    {
        isDivekicking = true;
        _animator.Play("p1_slide");
        int dir = (facingRight) ? 1 : -1;

        transform.rotation = Quaternion.AngleAxis(-45 * dir, Vector3.forward);
        float timer = 0.0f;

        while (timer < diveTime)
        {
            _velocity.x = Mathf.Lerp(_velocity.x, dir * diveKickForce.x, inAirDamping);
            _velocity.y = Mathf.Lerp(_velocity.y, diveKickForce.y, inAirDamping);
            _controller.move(_velocity * Time.deltaTime);
            timer += Time.deltaTime;
            yield return(null);
        }
    }
コード例 #25
0
    // Update is called once per frame
    void Update()
    {
        player = stats.target.GetComponent <player>();

        if (!stats.dead &&
            pauseState.instance.GetPauseState() != PAUSESTATE.PAUSED &&
            player.GetMoveState() != PlayerMoveState.DEAD)
        {
            CoolDown();

            CheckWall();

            if (_controller.isGrounded)
            {
                stats.SetMoveState(MinionMoveState.RUNNING);
            }
            else
            {
                stats.SetMoveState(MinionMoveState.MIDAIR);
            }

            if (actionTimer > 0.0f)
            {
                stats.SetActionState(MinionActionState.NULL);
            }
            else if (actionTimer <= 0.0f)
            {
                MoveFrom(stats.target);

                if (attackTimer <= 0.0f)
                {
                    Attack();
                    attackCountdown = false;
                    attackTimer     = 0.25f;
                    inRange         = false;
                }
            }

            // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control
            var smoothedMovementFactor = _controller.isGrounded ? stats.groundDamping : stats.inAirDamping; // how fast do we change direction?

            _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * stats.moveSpeed, Time.deltaTime * smoothedMovementFactor);

            _velocity.y += stats.gravity * Time.deltaTime;

            _controller.move(_velocity * Time.deltaTime);

            // grab our current _velocity to use as a base for all calculations
            _velocity = _controller.velocity;

            if (_controller._isGoingUpSlope && normalizedHorizontalSpeed > 0)
            {
                this.transform.position = new Vector3(transform.position.x, transform.position.y + _controller.skinWidth, transform.position.z);
            }
        }
    }
コード例 #26
0
    void Update()
    {
        Vector2 input = PlayerControls.Player.Move.ReadValue <Vector2>();

        bool dash = PlayerControls.Player.Dash.triggered;

        if (dash)
        {
            Vector2 moveDir = input * dashSpeed;

            Character.move(moveDir * Time.deltaTime);
        }
        else
        {
            Vector2 moveDir = input * MoveSpeed;

            Character.move(moveDir * Time.deltaTime);
        }
    }
コード例 #27
0
 public void ApplyMovement(Buttons buttons, float deltaTime)
 {
     if (buttons.Left)
     {
         characterController.move(Vector3.left * deltaTime * speed);
     }
     if (buttons.Up)
     {
         characterController.move(Vector3.up * deltaTime * speed);
     }
     if (buttons.Right)
     {
         characterController.move(Vector3.right * deltaTime * speed);
     }
     if (buttons.Down)
     {
         characterController.move(Vector3.down * deltaTime * speed);
     }
 }
コード例 #28
0
ファイル: PlayerController.cs プロジェクト: LiamBotha/Silt
    private void CheckCollisions()
    {
        if (playerColl.OnRightWall && currWallDir != 1)
        {
            currWallDir   = 1;
            isWallJumping = false;

            ResetCoroutines();

            if (isDashing)
            {
                playerVelocity.x = playerVelocity.x / 1.5f;
                playerVelocity.y = playerVelocity.y / 1.5f;

                controller.move(playerVelocity * Time.deltaTime);

                isDashing = false;
            }
        }
        else if (playerColl.OnLeftWall && currWallDir != -1)
        {
            currWallDir   = -1;
            isWallJumping = false;

            ResetCoroutines();

            if (isDashing)
            {
                playerVelocity.x = playerVelocity.x / 1.5f;
                playerVelocity.y = playerVelocity.y / 1.5f;

                controller.move(playerVelocity * Time.deltaTime);

                isDashing = false;
            }
        }

        if (isWallJumping && controller.isGrounded)
        {
            isWallJumping = false;
            currWallDir   = 0;
        }
    }
コード例 #29
0
    // Update is called once per frame
    void Update()
    {
        var velocity = _controller.velocity;

        if (_controller.isGrounded)
        {
            velocity.y = 0;
        }


        //Horizontaler SpielerInput
        float h = Input.GetAxis(horizontalInput);

        move = velocity.x;

        anim.SetFloat("Speed", Mathf.Abs(move));

        if (h > 0)
        {
            facingRight = true;
            velocity.x  = runSpeed;
            goRight();
        }

        else if (h < 0)
        {
            facingRight = false;
            velocity.x  = -runSpeed;
            goLeft();
        }

        else
        {
            velocity.x = 0;
        }

        //Vertikaler SpielerInput
        if (Input.GetButtonDown(jumpButton) && _controller.isGrounded)
        {
            var targetJumpHeight = 3.5f;
            velocity.y = Mathf.Sqrt(2f * targetJumpHeight * -gravity);
            anim.SetTrigger("Jump");
        }

        if (Input.GetButtonDown(fireButton))
        {
            anim.SetTrigger("Fire");
        }



        //Schwerkraft hinzufügen
        velocity.y += gravity * Time.deltaTime;
        _controller.move(velocity * Time.deltaTime);
    }
コード例 #30
0
    void Update()
    {
        // grab our current velocity to use as a base for all calculations
        velocity = controller.velocity;

        if (controller.isGrounded)
        {
            velocity.y = 0;
            isJumping  = false;
        }

        // horizontal input
        if (Input.GetKey(KeyCode.RightArrow))
        {
            velocity.x = runSpeed;
            goRight();

            if (controller.isGrounded)
            {
                animator.Play(runState);
            }
        }
        else if (Input.GetKey(KeyCode.LeftArrow))
        {
            velocity.x = -runSpeed;

            goLeft();

            if (controller.isGrounded)
            {
                animator.Play(runState);
            }
        }
        else
        {
            velocity.x = 0;

            if (controller.isGrounded)
            {
                animator.Play(idleState);
            }
        }

        if (Input.GetKey(KeyCode.UpArrow) && !isJumping)
        {
            velocity.y = Mathf.Sqrt(3f * jumpHeight * -gravity);
            animator.Play(jumpState);
            isJumping = true;
        }

        // apply gravity before moving
        velocity.y += gravity * Time.deltaTime;

        controller.move(velocity * Time.deltaTime);
    }