Exemple #1
0
    void Update()
    {
        float   x           = Input.GetAxis("Horizontal");
        float   z           = Input.GetAxis("Vertical");
        Vector3 flatForward = Camera.main.transform.forward;

        flatForward.y = 0.0f;
        Vector3 flatRight = Camera.main.transform.right;

        flatRight.y = 0.0f;
        Vector3 controlledMovement = flatForward.normalized * z + flatRight.normalized * x;

        System.Type t = currMovementState.GetState();
        if (t != currMovementState.GetType())
        {
            SetMovementState(t);
        }
        // TODO: remove first parameter to GetMovement and reference cc.velocity in the function
        // movement = currMovementState.GetMovement(movement, controlledMovement);
        movement = currMovementState.GetMovement(cc.velocity, controlledMovement);

        movement += Physics.gravity * Time.deltaTime;
        Vector3 frameMovement = movement * Time.deltaTime;

        cc.Move(frameMovement);

        // TODO: handle turning in movement states
        TurnTowards(controlledMovement);
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!ready)
        {
            return;
        }

        //DontGoThroughThings(player_collider, player_rb);
        //DontGoThroughThings(left_toe_collider, player_rb, delegate { right_foot_caught = true;});
        //DontGoThroughThings(right_toe_collider, player_rb, delegate { left_foot_caught = true; });

        InputTransform inp = new InputTransform();

        move_state.Move(inp, transform);
        anim.SetFloat(animation_speed_id, (float)move_state.anim_speed);
        anim.SetFloat(animation_direction_id, (float)move_state.anim_direction);
        anim.speed = (float)move_state.anim_speed;

        player_rb.useGravity = true;

        if (Input.GetButtonDown(jump_button) && move_state.is_grounded)
        {
            move_state = new JumpingMovementState(this);
            //GetComponent<Rigidbody>().AddForce(Vector3.up * 1.0f);
            right_foot_caught = false;
            left_foot_caught  = false;
        }
        else if (right_foot_caught || left_foot_caught)
        {
            move_state.FootGrounded();
        }
        else
        {
            move_state.FootUngrounded();
        }

        move_state.FixedUpdate();
        velocity = transform.TransformDirection(velocity);
        //Debug.Log($"velocity: {velocity}");
        player_rb.velocity = new Vector3(velocity.x, player_rb.velocity.y, velocity.z);
        //Debug.Log($"pos: {transform.localPosition}");
        Debug.Log(move_state.GetType().ToString());
    }
Exemple #3
0
        public override Rectangle EnemyHitBox()
        {
            Point size = SpriteFactory.ObjectSize(HealthState.GetType().Name + MovementState.GetType().Name);

            return(new Rectangle((int)Position.X, (int)Position.Y - size.Y, size.X, size.Y));
        }
Exemple #4
0
    void Update()
    {
        if (!isLocalPlayer)
        {
            //controller.Move(velocity * Time.deltaTime);
            UpdateDirection();
            return;
        }
        //inputs.UpdateInputs();
        
        MovementState next = movementState.UpdateState(ref velocity, ref externalForce);

        ChooseNextState(ref next);

        //HandleCollisions();

        if (next != null)
        {
            movementState.OnExit(ref velocity, ref externalForce);
            next.OnEnter(ref velocity, ref externalForce);
            movementState = next;
            CmdUpdateMovementState(movementState.GetType().ToString());
        }

        //handle blocking/parrying
        if (hitWith != null)
        {
            if (!hitWith.isActiveAndEnabled || (weapon.InHand && shield.TakeHit()))
            {
                hitWith = null;
            }
            //else if (!weapon.InHand && inputs.parry.Down)
            else if (!weapon.InHand && InputPlayer.GetButtonDown("Parry"))
            {
                //steal weapon like a badass
                weapon.InHand = true;
                hitWith.InHand = false;
                hitWith = null;
            }
        }

        //if (inputs.weaponSpecial.Down)
        if (InputPlayer.GetButtonDown("Weapon Special"))
        {
            weapon.Special();
        }

        //update animation states
        if (anim != null)
        {
            UpdateDirection();
            float velMag = Mathf.Abs(velocity.x);
            anim.SetFloat("HorizontalSpeed", velMag);
            anim.SetBool("OnGround", movementState is OnGround);
            //anim.SetBool("OnDash", movementState is OnDash);
            anim.SetBool("OnWall", movementState is OnWall);
            //anim.SetBool("InAttack", movementState is InAttack);
            anim.SetBool("InAir", movementState is InAir);
            anim.SetBool("Hit", hitWith != null);
        }
    }