Ejemplo n.º 1
0
 void Start()
 {
     input             = GetComponent <InputController>();
     physicsController = GetComponent <PhysicsController>();
     actionController  = GetComponent <ActionController>();
     state             = CharacterState.State.Idle;
 }
Ejemplo n.º 2
0
 private void OnEnable()
 {
     previousState = characterState.state;
     characterState.SetState(CharacterState.State.Cinematic);
     animator.TransitionPlay(cinematic);
     hasPlayedAudio = false;
 }
Ejemplo n.º 3
0
        private void FixedUpdate()
        {
            ComputeVelocity();
            Vector2 verticalVelocity = ComputeVerticalVelocity();

            velocity  += verticalVelocity;
            velocity.x = targetVelocity.x;

            switch (state)
            {
            case CharacterState.State.JUMPING:
            case CharacterState.State.FALLING:
                if (velocity.y < 0)
                {
                    this.state = CharacterState.Falling();
                }
                break;
            }


//			Debug.Log($"velocity={velocity}, Time.smoothDeltaTime={Time.smoothDeltaTime}");
            Vector2 deltaPosition = velocity * Time.smoothDeltaTime;
//			Debug.Log($"deltaPosition={deltaPosition.x}");
            Vector2 moveAlongGround = new Vector2(groundNormal.y, -groundNormal.x);
            Vector2 move            = moveAlongGround * deltaPosition.x;

            DoMovement(move, false);

            move = Vector2.up * deltaPosition.y;

            DoMovement(move, true);
        }
 void Update()
 {
     CharacterState.State state = characterState.state;
     if (previousState != state)
     {
         previousState = state;
         UpdateState();
     }
 }
Ejemplo n.º 5
0
        private void DoMovement(Vector2 move, bool yMovement)
        {
            float distance = move.magnitude;

            // If distance is past threshold
            if (distance > minMoveDistance)
            {
                // Cast rays from body (excluding our own collider)
                int count = rb2d.Cast(move, contactFilter, hitBuffer, distance + shellRadius);
                hitBufferList.Clear();
                // Collect all contacts from raycasts
                for (int i = 0; i < count; i++)
                {
                    hitBufferList.Add(hitBuffer[i]);
                }

                // Check each ray to see if the distance between it and the ground is low enough
                for (int index = 0; index < hitBufferList.Count; index++)
                {
                    RaycastHit2D hit           = hitBufferList[index];
                    Vector2      currentNormal = hit.normal;
                    if (currentNormal.y > minGroundNormalY)
                    {
                        this.state = CharacterState.Default();
                        if (yMovement)
                        {
                            groundNormal    = currentNormal;
                            currentNormal.x = 0;
                        }
                    }

                    float projection = Vector2.Dot(velocity, currentNormal);
                    if (projection < 0)
                    {
                        velocity = velocity - projection * currentNormal;
                    }

                    float modifiedDistance = hit.distance - shellRadius;
                    distance = modifiedDistance < distance ? modifiedDistance : distance;
                }
            }
            rb2d.position = rb2d.position + move.normalized * distance;
        }
 public void UpdateState()
 {
     CharacterState.State state = characterState.state;
     if (animator.runtimeAnimatorController.name == "Bear")
     {
         if (state == CharacterState.State.Idle)
         {
             animator.TransitionPlay("Idle Bear");
         }
         if (state == CharacterState.State.Movement)
         {
             animator.TransitionPlay("Walk Bear");
         }
     }
     else if (name.Contains("Woman"))
     {
         if (state == CharacterState.State.Idle)
         {
             animator.TransitionPlay("Woman Idle Pistol");
         }
         if (state == CharacterState.State.Movement)
         {
             animator.TransitionPlay("Woman Walk Pistol");
         }
     }
     if (grabber && grabber.state == Grabber.State.Hold)
     {
         if (state == CharacterState.State.Idle)
         {
             animator.TransitionPlay("Grab Idle");
         }
         if (state == CharacterState.State.Movement)
         {
             animator.TransitionPlay("Grab Walk");
         }
     }
     else if (attack.weapon.attackType == Weapon.AttackType.Swing)
     {
         if (state == CharacterState.State.Idle)
         {
             animator.TransitionPlay("Idle Axe");
         }
         if (state == CharacterState.State.Movement)
         {
             animator.TransitionPlay("Walk Axe");
         }
     }
     else if (attack.weapon.attackType == Weapon.AttackType.Shoot)
     {
         if (state == CharacterState.State.Idle)
         {
             animator.TransitionPlay("Idle Musket");
         }
         if (state == CharacterState.State.Movement)
         {
             animator.TransitionPlay("Walk Musket");
         }
     }
     else
     {
         if (tag == "Player")
         {
             if (state == CharacterState.State.Idle)
             {
                 animator.TransitionPlay("Abe Idle");
             }
             if (state == CharacterState.State.Movement)
             {
                 animator.TransitionPlay("Abe Walk");
             }
             if (state == CharacterState.State.Dead)
             {
                 animator.TransitionPlay("Abe Death");
             }
         }
         else
         {
             if (state == CharacterState.State.Idle)
             {
                 animator.TransitionPlay("Idle");
             }
             if (state == CharacterState.State.Movement)
             {
                 animator.TransitionPlay("Walk");
             }
         }
     }
     if (state == CharacterState.State.StartGame)
     {
         animator.Play("Knock Down On Ground");
     }
 }