public virtual void WalkControl()
        {
            if (walktimer >= 0)
            {
                walktimer -= Time.deltaTime;

                /*
                 * if (Physics2D.Raycast(transform.position, direction * 4))
                 * {
                 *  direction *= -1;
                 * }
                 */
            }
            else
            {
                int random = Random.Range(0, 2);
                switch (random)
                {
                case 0:
                    Move();
                    CHARACTER_STATE = CHARACTER_STATES.STATE_MOVING;
                    direction       = new Vector2(Random.Range(-2, 2), Random.Range(-2, 2)).normalized;
                    break;

                case 1:
                    CHARACTER_STATE = CHARACTER_STATES.STATE_IDLE;
                    break;
                }
                walktimer = Random.Range(0.6f, 3);
            }
        }
        protected void FixedUpdate()
        {
            if (damage_timer > 0)
            {
                damage_timer     -= Time.deltaTime;
                rendererObj.color = Color.red;
            }
            else
            {
                rendererObj.color = Color.white;
            }

            if (AI_QUEUED_STATES.Count > 0)
            {
                if (AI_QUEUED_STATES.Peek().timer >= 0.1f)
                {
                    if (ai_timer > 0)
                    {
                        ai_timer = ai_timer - Time.deltaTime;
                    }
                    else
                    {
                        AI_QUEUED_STATES.Pop();
                    }
                }
                AI_QUEUED_STATES.Peek().func();
            }

            if (health <= 0)
            {
                if (CHARACTER_STATE != CHARACTER_STATES.STATE_DEFEAT)
                {
                    AfterDefeat();
                    CHARACTER_STATE = CHARACTER_STATES.STATE_DEFEAT;
                }
            }
            if (CHARACTER_STATE == CHARACTER_STATES.STATE_IDLE)
            {
                rbody2d.velocity *= velSlip;
            }
            Move();
            Z_offset += gravity;
            if (Z_offset > 0)
            {
                grounded = false;
                gravity -= Time.deltaTime * wldgravity;
            }
            else
            {
                if (!grounded)
                {
                    OnGround();
                }
                grounded = true;
                Z_offset = 0;
            }
        }
 public void Dash(float delay, float sped)
 {
     if (dashdelay > 0)
     {
         return;
     }
     dashdelayStart = delay;
     dashdelay      = delay;
     if (rbody2d != null)
     {
         Pushforce(direction, sped);
     }
     CHARACTER_STATE = CHARACTER_STATES.STATE_DASHING;
 }
 public void Hurt(o_bullet b)
 {
     CHARACTER_STATE = CHARACTER_STATES.STATE_HURT;
     HurtFunction(b.attack_pow);
     Pushforce(b.direction, 135f);
 }
 public void CrashOnDash()
 {
     crashTimer      = 1.4f;
     CHARACTER_STATE = CHARACTER_STATES.STATE_NOTHING;
 }
 public virtual void AfterDash()
 {
     CHARACTER_STATE = CHARACTER_STATES.STATE_MOVING;
 }
        void Move()
        {
            switch (CHARACTER_STATE)
            {
            case CHARACTER_STATES.STATE_NOTHING:
                if (crashTimer > 0)
                {
                    crashTimer -= Time.deltaTime;
                }
                if (crashTimer != -1)
                {
                    if (crashTimer <= 0)
                    {
                        CHARACTER_STATE = CHARACTER_STATES.STATE_IDLE;
                    }
                }
                break;

            case CHARACTER_STATES.STATE_IDLE:
                if (rbody2d != null)
                {
                    rbody2d.velocity *= 0.85f;
                }
                break;

            case CHARACTER_STATES.STATE_MOVING:
                if (rbody2d != null)
                {
                    rbody2d.velocity = direction * terminalspd;
                }
                //transform.Translate(velocity * Time.deltaTime);
                break;

            case CHARACTER_STATES.STATE_FALLING:
                transform.position -= new Vector3(0, 5, 0);
                if (transform.position.y <= fallposy)
                {
                    CHARACTER_STATE = CHARACTER_STATES.STATE_MOVING;
                }
                break;

            case CHARACTER_STATES.STATE_HURT:
                if (damage_timer <= 0)
                {
                    CHARACTER_STATE = CHARACTER_STATES.STATE_MOVING;
                }
                break;

            case CHARACTER_STATES.STATE_DASHING:
                if (dashdelay <= 0)
                {
                    AfterDash();
                }
                else
                {
                    Collider2D c = Physics2D.OverlapBox((Vector2)transform.position + (direction * 10), collision.size, 0);
                    if (c != null)
                    {
                        if (c.name == "Collision")
                        {
                            CrashOnDash();
                            dashdelay = 0;
                        }
                    }
                    if (dashdelay < dashdelayStart / 2)
                    {
                        if (!AI)
                        {
                            if (!Input.GetKey(KeyCode.LeftShift))
                            {
                                dashdelay = 0;
                            }
                        }
                    }
                    //rbody.velocity += direction * 6;
                    dashdelay -= Time.deltaTime;
                }
                //positioninworld += (Vector3)new Vector2(velocity.x, velocity.y) * 15 * Time.deltaTime;
                break;
            }
            // transform.Translate((Vector3)rbody2d.velocity * Time.deltaTime);

            if (SpriteObj != null)
            {
                SpriteObj.transform.position = new Vector3(transform.position.x, transform.position.y + Z_offset);
            }

            /*
             * if (rbody2d == null)
             * {
             *  positioninworld += (Vector3)new Vector2(velocity.x, velocity.y) * Time.deltaTime;
             *
             *
             *  Vector2 composite_pos = positioninworld;
             *
             *  if (parentTrans != null)
             *      composite_pos = parentTrans.positioninworld;
             *  positioninworld = composite_pos;
             *  transform.position = new Vector2(composite_pos.x, composite_pos.y + Z_offset);
             * }
             */
            if (IS_KINEMATIC)
            {
                collision.isTrigger = false;
                COLLISIONDET();
            }
            else
            {
                collision.isTrigger = true;
            }
        }