Esempio n. 1
0
 private void Update()
 {
     losToPlayer = false;
     if ((player.transform.position - transform.position).sqrMagnitude <= sightRange * sightRange)
     {
         losToPlayer = Utility.lineOfSight(gameObject, player);
     }
     if (losToPlayer)
     {
         if (!fearParticles.isPlaying)
         {
             fearParticles.Play();
         }
     }
     else
     {
         if (fearParticles.isPlaying)
         {
             fearParticles.Stop();
         }
     }
     if (rb2d.velocity.magnitude < 0.1f)
     {
         hm.addIntegrity(healsPerSecond * Time.deltaTime);
         if (hm.getIntegrity() == hm.maxIntegrity)
         {
             healing = false;
         }
     }
 }
Esempio n. 2
0
 public void trigger()
 {
     if (chargesLeft > 0)
     {
         fta.processHoldGesture(transform.position, chargeTime, true);
         chargeTime = 0;
         setChargesLeft(chargesLeft - 1);
     }
     else
     {
         if (destroyedOnLastCharge)
         {
             HardMaterial hm = GetComponent <HardMaterial>();
             hm.addIntegrity(-hm.maxIntegrity);
         }
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (activeMove && isGrounded())
     {
         float tempSpeed = speed;
         if (rb2d.velocity.magnitude < speed / 4)
         {
             tempSpeed *= speed * 2;
         }
         if (hm.getIntegrity() < hm.maxIntegrity / 4 || healing)
         {
             healing   = true;
             tempSpeed = 0;
         }
         if (tempSpeed > 0)
         {
             rb2d.AddForce(rb2d.mass * direction * tempSpeed);
         }
         if (rb2d.velocity.magnitude > maxSpeedReached)
         {
             maxSpeedReached = rb2d.velocity.magnitude;
         }
         //Cliff detection
         if (senseInFront() == null)                       //there's a cliff up ahead
         {
             if (!Utility.lineOfSight(gameObject, player)) //nothing between it and the player
             {
                 switchDirection();
                 rb2d.AddForce(rb2d.mass * direction * rb2d.velocity.magnitude * 4);
             }
         }
         if (rb2d.velocity.magnitude < 0.01f)
         {
             switchDirection();
         }
     }
     if (rb2d.velocity.magnitude < 0.1f)
     {
         hm.addIntegrity(healsPerSecond * Time.deltaTime);
         if (hm.getIntegrity() == hm.maxIntegrity)
         {
             healing = false;
         }
     }
 }
Esempio n. 4
0
    private bool teleport(Vector3 targetPos, bool playSound)//targetPos is in world coordinations (NOT UI coordinates)
    {
        if (teleportTime <= Time.time)
        {
            if (!isGrounded())
            {
                airPorts++;
            }
            if (airPorts > maxAirPorts)
            {
                //2017-03-06: copied from https://docs.unity3d.com/Manual/AmountVectorMagnitudeInAnotherDirection.html
                float upAmount = Vector3.Dot((targetPos - transform.position).normalized, -gravity.Gravity.normalized);
                teleportTime = Time.time + exhaustCoolDownTime * upAmount;
            }
            //Get new position
            Vector3 newPos = targetPos;

            //Actually Teleport
            Vector3 oldPos = transform.position;
            transform.position = newPos;
            showTeleportEffect(oldPos, newPos);
            if (playSound)
            {
                if (groundedWall && wca.enabled)
                {
                    AudioSource.PlayClipAtPoint(wca.wallClimbSound, oldPos);
                }
                else
                {
                    AudioSource.PlayClipAtPoint(teleportSound, oldPos);
                }
            }
            teleportRangeParticalController.activateTeleportParticleSystem(true, 0);
            //Health Regen
            hm.addIntegrity(Vector2.Distance(oldPos, newPos));
            //Momentum Dampening
            if (rb2d.velocity.sqrMagnitude > 0.001f)//if Merky is moving
            {
                Vector3 direction = newPos - oldPos;
                float   newX      = rb2d.velocity.x;//the new x velocity
                float   newY      = rb2d.velocity.y;
                if (Mathf.Sign(rb2d.velocity.x) != Mathf.Sign(direction.x))
                {
                    newX = rb2d.velocity.x + direction.x;
                    if (Mathf.Sign(rb2d.velocity.x) != Mathf.Sign(newX))
                    {//keep from exploiting boost in opposite direction
                        newX = 0;
                    }
                }
                if (Mathf.Sign(rb2d.velocity.y) != Mathf.Sign(direction.y))
                {
                    newY = rb2d.velocity.y + direction.y;
                    if (Mathf.Sign(rb2d.velocity.y) != Mathf.Sign(newY))
                    {//keep from exploiting boost in opposite direction
                        newY = 0;
                    }
                }
                rb2d.velocity = new Vector2(newX, newY);
            }
            //Gravity Immunity
            grounded = false;
            velocityNeedsReloaded = false;//discards previous velocity if was in gravity immunity bubble
            gravityImmuneTime     = 0f;
            shouldGrantGIT        = true;
            mainCamCtr.delayMovement(0.3f);
            checkGroundedState(true);//have to call it again because state has changed
            return(true);
        }
        return(false);
    }