Example #1
0
    public void Update(IVIHand hand)
    {
        if (!hand.IsDetected || IsBeingPerformed)
        {
            Force             = new Vector3(0, 0, 0);
            FirstStepPosition = new Vector3(0, 0, 0);
            FirstStepTime     = 0f;
            IsBeingPerformed  = false;
            state             = ThrowingState.Undefined;
            return;
        }


        if (hand.Detectors.ClosedFist.IsActive &&
            Vector3.Distance(hand.LeapHand.PalmPosition.ToVector3(), IVISession.User.transform.position) <= MaxBeginDistanceFromUser)
        {
            FirstStepPosition = hand.LeapHand.PalmPosition.ToVector3();
            FirstStepTime     = Time.time;
            state             = ThrowingState.FirstStep;
            return;
        }
        if (state == ThrowingState.FirstStep &&
            !hand.Detectors.ClosedFist.IsActive &&
            (Vector3.Distance(FirstStepPosition, hand.LeapHand.PalmPosition.ToVector3()) / (Time.time - FirstStepTime)) >= MinVelocityToThrow)
        {
            Direction        = (hand.LeapHand.PalmPosition.ToVector3() - FirstStepPosition).normalized;
            Velocity         = Vector3.Distance(FirstStepPosition, hand.LeapHand.PalmPosition.ToVector3()) / (Time.time - FirstStepTime);
            Force            = Velocity * Direction;
            state            = ThrowingState.ThrowStep;
            IsBeingPerformed = true;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (throwingState == ThrowingState.idle && Input.GetMouseButtonDown(1))
        {
            firingAngle = Vector3.zero;

            crystalGO.SetActive(false);
            //ropeSpawn.Reset();
        }
        else if (throwingState == ThrowingState.idle && Input.GetMouseButtonDown(0))
        {
            intialMousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

            /*
             * // Charging logic
             * var stwp = (Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane)));
             * firingAngle = (stwp - playerGO.transform.position);
             * firingAngle.z = 0;
             * firingAngle = firingAngle.normalized;
             * firingAngle.x = firingAngle.x * 7;
             */

            throwingState = ThrowingState.charging;
        }
        else if (throwingState == ThrowingState.charging)
        {
            //CurrentCharge += chargeRate * Time.deltaTime;

            if (Input.GetMouseButtonUp(0))
            {
                Fire();
            }
        }
    }
Example #3
0
 public void ReturnToPlayer()
 {
     hitbox.RestoreGetHitBools();
     if (kState == ThrowingState.Thrown)
     {
         kState = ThrowingState.Recalling;
     }
 }
Example #4
0
    //private void FailedUpdate()
    //{
    //    if (hasBeenThrown==false)
    //    {
    //        //reset vars
    //        boomerangFlag = false;
    //        boomerangTime = 10;
    //        turnAmount = 0;
    //        state = 0;
    //        direction = 0;
    //        doCollision = true;
    //    }
    //    else
    //    {
    //        if (boomerangFlag)
    //        {
    //            doCollision = false;
    //            switch (state)
    //            {
    //                case 0://spin state
    //                    var rspd = 50;//rotation speed
    //                    velocity += transform.right.normalized;
    //                    transform.Translate(velocity);
    //                    //scale
    //                    direction += rspd * orient * Time.deltaTime;//gradually change direction to create path of boomerang
    //                    if (turnAmount >= 190)//once boomerange rotates 190 degrees it goes to the returning state
    //                    {
    //                        state = 1;
    //                    }
    //                    else
    //                        turnAmount += rspd * Time.deltaTime;//increment degrees we have rotated
    //                    break;
    //                case 1://throw state
    //                    var pdir = transform.position - (thrower.transform.position + Vector3.down * 16);//direction to face towards the thrower
    //                    transform.forward = Vector3.RotateTowards(transform.forward, pdir, 3f * Time.deltaTime,0f); //smoothly shift current dir to previous dir
    //                    velocity += transform.right.normalized;//move
    //                    transform.Translate(velocity);
    //                    //check to see if spin state is needed
    //                    if (Vector2.Distance(transform.position, thrower.transform.position) <=8)//is boomerang within 8 units of thrower
    //                        if (orient==1 && transform.position.x>thrower.transform.position.x+16|| orient == -1 && transform.position.x < thrower.transform.position.x - 16)//if 16 units past thrower
    //                        {
    //                            //set orient relative to current dir
    //                            if (direction > 90 && direction < 270)
    //                                orient = -1;
    //                            else
    //                                orient = 1;

    //                            turnAmount = 0;//reset rot timer
    //                            //set initial dir for spin based on orient
    //                            if (orient==1)
    //                                direction=0;
    //                            else
    //                                direction=180;

    //                            state = 0;
    //                        }
    //                    if (Vector2.Distance(transform.position, thrower.transform.position) <= returnDistance){ TryGrabKinzecter(); }
    //                    break;

    //            }
    //        }
    //        else
    //        {
    //            if (boomerangTime>0)
    //            {
    //                boomerangTime -= 4*Time.deltaTime;
    //                orient = Mathf.Sign(velocity.x);
    //            }
    //            else
    //            {
    //                boomerangFlag = true;
    //                //set initial dir for spin based on orient
    //                if (orient == 1)
    //                    direction = 0;
    //                else
    //                    direction = 180;
    //            }
    //        }

    //    }
    //}
    public void ThrowKinzecter(CharacterObject player, Vector3 throwDir)
    {
        //thrower = player;
        //hasBeenThrown = true;
        this.transform.position = player.transform.position + throwDir * returnDistance;
        kzRB.isKinematic        = false;
        kzRB.AddForce(throwDir * kzSpeed, ForceMode2D.Impulse);
        audioManager.PlaySound(flightSound);
        kState = ThrowingState.Thrown;
    }
Example #5
0
 private void TryGrabKinzecter()
 {
     if (Vector3.Distance(transform.position, thrower.transform.position) <= returnDistance)
     {
         kState = ThrowingState.WithPlayer;
         //velocity = Vector2.zero;
         kzRB.isKinematic = true;
         //hasBeenThrown = false;
         thrower.isKinzecterOut = false;
         Destroy(gameObject, .2f);
     }
 }
Example #6
0
    //[Header("Boomerang")]
    //public bool hasBeenThrown = false;//collision
    //public bool doCollision = false;//collision
    //public bool boomerangFlag = false;//ai on
    //public float boomerangTime = 20;//time spent turning back to the player
    //public float orient = 0; //direction boomerang turns  in the boomerang state
    //public float turnAmount = 0; //how much boomerang has turned, used to end the state
    //public float direction; //
    //public int state;
    //public Vector3 velocity;
    //public Vector3 friction = new Vector3(0.95f, 0.99f, 0.95f);
    private void Awake()
    {
        kzSprite     = GetComponent <SpriteRenderer>();
        kzRB         = GetComponent <Rigidbody2D>();
        kzColl       = GetComponent <Collider2D>();
        thrower      = GameEngine.gameEngine.mainCharacter;
        hitbox       = GetComponent <Hitbox>();
        audioManager = AudioManager.instance;
        if (audioManager == null)
        {
            Debug.LogError("No Audio Manager in Scene");
        }

        kState = ThrowingState.Recalling;
    }
    public void Fire()
    {
        //Debug.Log("FIRE         Charge:" + currentCharge);

        Vector2 finalMousePosition = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
        Vector2 difference         = finalMousePosition - intialMousePosition;

        Vector2 differenceNormalized = difference.normalized;

        CurrentCharge = difference.magnitude / 750f;// * 100000000000f;
        crystalGO.GetComponent <Rigidbody2D>().bodyType = RigidbodyType2D.Dynamic;
        crystalGO.transform.position = playerGO.transform.position;
        crystalGO.SetActive(true);
        crystalGO.GetComponent <Rigidbody2D>().AddForce(new Vector2(differenceNormalized.x * firingPower, differenceNormalized.y * firingPower) * CurrentCharge);

        followCrystal.state = FollowCrystal.FollowCrystalState.saving;

        //CurrentCharge = -1f;
        throwingState            = ThrowingState.idle;
        crystalCollision.enabled = true;
        playerWalkJump.enabled   = false;
    }
 // Start is called before the first frame update
 void Start()
 {
     throwingState = ThrowingState.idle;
 }