Exemplo n.º 1
0
 public void DisableAnim()
 {
     StartCoroutine(SlowDown());
     ReleaseItem(false);
     _isDisabled = true;
     _animator.SetInteger("State", (int)ANIMSTATE.Hurt);
     _previousAnimState = ANIMSTATE.Hurt;
 }
Exemplo n.º 2
0
 void Start()
 {
     if (_manager == null)
     {
         _manager = References.Instance._characterManager;
     }
     if (_rigidbody == null)
     {
         _rigidbody = GetComponent <Rigidbody2D>();
     }
     if (_animator == null)
     {
         _animator = GetComponent <Animator>();
     }
     _isDisabled        = false;
     _cauldron          = null;
     _previousAnimState = ANIMSTATE.Down;
 }
Exemplo n.º 3
0
        private void SetSpriteDirection(float XVelocity, float YVelocity, float velocity)
        {
            if (!_isDisabled)
            {
                _animator.SetFloat("Velocity", velocity);
                ANIMSTATE newState = _previousAnimState;
                if (newState != ANIMSTATE.Hurt)
                {
                    if (Mathf.Abs(XVelocity) > Mathf.Abs(YVelocity))
                    {
                        if (XVelocity < 0)
                        {
                            newState = ANIMSTATE.Left;
                        }
                        else if (XVelocity > 0)
                        {
                            newState = ANIMSTATE.Right;
                        }
                    }
                    else
                    {
                        if (YVelocity < 0)
                        {
                            newState = ANIMSTATE.Down;
                        }
                        else if (YVelocity > 0)
                        {
                            newState = ANIMSTATE.Up;
                        }
                    }
                }
                else
                {
                    newState = ANIMSTATE.Down;
                }

                _previousAnimState = newState;
                SetAnimInt((int)newState);
                if (_heldObject != null)
                {
                    SortHeldObject(newState);
                }
            }
        }
Exemplo n.º 4
0
 private void SortHeldObject(ANIMSTATE direction)
 {
     if (direction == ANIMSTATE.Down)
     {
         _heldObject.GetComponentInChildren <SpriteRenderer>().sortingLayerName = "CollectablesFrontOfPlayer";
         _heldObject.transform.localPosition = new Vector3(0, -1.5f, 0);
     }
     if (direction == ANIMSTATE.Up)
     {
         _heldObject.GetComponentInChildren <SpriteRenderer>().sortingLayerName = "CollectablesBehindPlayer";
         _heldObject.transform.localPosition = new Vector3(0, 0, 0);
     }
     if (direction == ANIMSTATE.Left)
     {
         _heldObject.GetComponentInChildren <SpriteRenderer>().sortingLayerName = "CollectablesFrontOfPlayer";
         _heldObject.transform.localPosition = new Vector3(-1.2f, -1, 0);
     }
     if (direction == ANIMSTATE.Right)
     {
         _heldObject.GetComponentInChildren <SpriteRenderer>().sortingLayerName = "CollectablesFrontOfPlayer";
         _heldObject.transform.localPosition = new Vector3(1.2f, -1, 0);
     }
 }
Exemplo n.º 5
0
 // Use this for initialization
 void Start()
 {
     animState = ANIMSTATE.IDLE;
     acceleration = Vector3.zero;
     velocity = Vector3.zero;
     collisionFlags = CollisionFlags.None;
     controller = gameObject.GetComponent<CharacterController>();
     Transform charModel = transform.Find( "Robin" );
     if (charModel)
     {
         Debug.Log ("Found robin");
         figure = charModel.gameObject;
     }
     anim = figure.animation;
     Debug.Log ("Found anim: " + anim.ToString());
     onGround = false;
     triggerInteraction = false;
     yrot = 180.0f;
     targetyrot = 180.0f;
     hurtTimer = 0.0f;
     suppressInputTimer = 0.0f;
 }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        float dt = Time.deltaTime;
        float lastx = transform.position.x;
        triggerInteraction = false;

        Vector3 vinput = Vector3.zero;
        if (suppressInputTimer<=0.0f)
        {
            vinput.x = Input.GetAxisRaw("Horizontal");
            vinput.y = Input.GetAxisRaw("Vertical");
            if (vinput.x>0)
                targetyrot = 91.0f;
            else if (vinput.x<0)
                targetyrot = 269.0f;
        }
        else
            suppressInputTimer -= dt;

        if (onGround)
            acceleration = vinput * inputScale;
        else if (!controller.isGrounded)		// From previous frame
            acceleration = vinput * inputScaleJumping;
        else
            acceleration = Vector3.zero;

        if (onGround)
        {
            velocity.y = 0.0f;
            if (vinput.y > 0.1f)
            {
                //Debug.Log( "JUMP at " + velocityJump + " in dt=" + dt);
                velocity.y = velocityJump;
                onGround = false;
                animState = ANIMSTATE.JUMP_LAUNCH;
            }
            else if (vinput.y < -0.1f)
            {
                triggerInteraction = true;
            }
        }

        // Damp horizontal acceleration
        if (acceleration.x > inputDamping*dt)
        {
            acceleration.x -= inputDamping*dt;
        }
        else if (acceleration.x < -inputDamping*dt)
        {
            acceleration.x += inputDamping*dt;
        }
        else
            acceleration.x = 0.0f;
        acceleration.y = -0.98f;
        acceleration.z = 0.0f;

        velocity += acceleration * dt;
        if (velocity.x > 0.0f)
        {
            if (onGround)
                velocity.x -= frictionGround*dt;
            else
                velocity.x -= frictionAir*dt;

            if (velocity.x < 0.0f)
                velocity.x = 0.0f;
            else if (velocity.x > velocityMax)
                velocity.x = velocityMax;
        }
        else if (velocity.x < 0.0f)
        {
            if (onGround)
                velocity.x += frictionGround*dt;
            else
                velocity.x += frictionAir*dt;

            if (velocity.x > 0.0f)
                velocity.x = 0.0f;
            else if (velocity.x < -velocityMax)
                velocity.x = -velocityMax;
        }
        else
            velocity.x = 0.0f;

        //
        // Move and collide
        //
        onGround = false;
        collisionFlags = controller.Move( velocity );
        if (controller.isGrounded)
        {
            if (surface_normal.y > 0.7f)
                onGround = true;
            else if (suppressInputTimer < 0.1f)
                suppressInputTimer = 0.1f;
        }
        if ((collisionFlags & CollisionFlags.CollidedBelow) > 0)
        {
            //velocity.y *= -0.5f;
            //acceleration.y = 0.0f;
        }
        if ((collisionFlags & CollisionFlags.CollidedAbove) > 0)
        {
            //velocity.y *= -0.1f;
            //acceleration.y = 0.0f;
        }
        if ((collisionFlags & CollisionFlags.CollidedSides) > 0)
        {
            velocity.x *= -0.8f;
            acceleration.x = 0.0f;
        }

        //
        // Update facing
        //
        /*
        if (transform.position.x > lastx)
            targetyrot = 90.0f;
        else if (transform.position.x < lastx)
            targetyrot = 270.0f;
        */
        yrot = Mathf.MoveTowardsAngle( yrot, targetyrot, turnSpeed * dt );

        Vector3 euler = Vector3.zero;
        euler.y = yrot;
        transform.localEulerAngles = euler;

        //
        // Update anim
        //
        /*
        if (hurtTimer>0.0f)
        {
            anim.CrossFade("plr_recoil", 0.1f);
            hurtTimer -= dt;
        }
        else
        */
        if (!onGround)
        {
            if (animState==ANIMSTATE.JUMP_LAUNCH)
            {
                anim.CrossFade("Jump", 0.1f);
                animState = ANIMSTATE.JUMP_IDLE;
            }
        }
        else if (Mathf.Abs(velocity.x) > 0.02f)
        {
            anim.CrossFade("Walk");
        }
        else
        {
           	anim.CrossFade("Idle");
        }
    }
Exemplo n.º 7
0
 // Use this for initialization
 void Start()
 {
     animState = ANIMSTATE.IDLE;
     acceleration = Vector3.zero;
     velocity = Vector3.zero;
     collisionFlags = CollisionFlags.None;
     controller = gameObject.GetComponent<CharacterController>();
     figure = transform.Find( "figure" ).gameObject;
     anim = figure.animation;
     Debug.Log ("Found anim: " + anim.ToString());
     onGround = false;
     yrot = 180.0f;
     targetyrot = 180.0f;
     holding_firefly = 0;
     hurtTimer = 0.0f;
     suppressInputTimer = 0.0f;
 }