Esempio n. 1
0
	// Use this for initialization
	void Start () {
		peo = this.GetComponent<PE_Obj>();
		enemy = this.GetComponent<Enemy>();

		initial_position = this.transform.position;
		initial_direciton = GroundDirection;

		UpdateSpriteRotation();
	}
Esempio n. 2
0
 override protected void ResolveCollisionWith(PE_Obj that)
 {
     switch (that.coll)
     {
     case PE_Collider.platform:                 // collide with platform
         Vector3 thatP = that.transform.position;
         Vector3 delta = (pos1 - this.transform.lossyScale / 2) - (thatP - that.transform.lossyScale / 2);
         if (delta.y >= 0 && vel.y <= 0)                       // Check coming from above and moving down
         {
             Vector3 newPos = transform.position;
             newPos.y           = thatP.y + (this.transform.lossyScale.y / 2) + (that.transform.lossyScale.y / 2);
             transform.position = newPos;
             vel.y = 0;
             vel.x = 0;
         }
         break;
     }
 }
Esempio n. 3
0
    void OnTriggerEnter(Collider other)
    {
        // Ignore collisions of still objects (moving handles collision)
        if (still)
        {
            return;
        }

        //
        PE_Obj otherPEO = other.GetComponent <PE_Obj>();

        if (otherPEO == null)
        {
            return;
        }

        ResolveCollisionWith(otherPEO);
    }
    //need to make this work with moving down to the lane and reducing accel
    //this is for top wall (tag the walls)
    void OnTriggerStay(Collider other)
    {
        /*Bike bikeScript = other.GetComponent<Bike> ();
         * PE_Obj bikePEO = other.GetComponent<PE_Obj> ();
         *
         * if (bikeScript.curDirIn != Bike.DirInput.UP) {
         *      bikePEO.vel.z = 0f;
         *      //tweak
         *      bikePEO.acc.x = -3f;
         * }*/

        PE_Obj bikePEO = other.GetComponent <PE_Obj> ();

        if (bikePEO == null)
        {
            return;
        }

        bikePEO.vel.z = 0f;
        if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
        {
            //bikePEO.vel.z = 0f;
            if (bikePEO.vel.x > wallSpeed)
            {
                bikePEO.acc.x = -3f;
            }
            //update these values if we tweak bike.cs
            else if (bikePEO.vel.x < wallSpeed)
            {
                if (Input.GetKey(KeyCode.X) || Input.GetKey(KeyCode.Period))
                {
                    bikePEO.acc.x = 3.25f;
                }
                else if (Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.Comma))
                {
                    bikePEO.acc.x = 5f;
                }
            }
            else
            {
                bikePEO.acc.x = 0f;
            }
        }
    }
Esempio n. 5
0
    override protected void ResolveCollisionWith(PE_Obj that)
    {
        switch (that.coll)
        {
        case PE_Collider.friendlyBullet:                 // collide with friendlyBullet
            // Kill bullet
            PhysEngine.objs.Remove(that.GetComponent <PE_Obj>());
            Destroy(that.gameObject);

            // Instantiate Powerup
            GameObject powerupGO = (GameObject)Instantiate(powerupPrefab);
            powerupGO.transform.position = this.transform.position;
            powerupGO.GetComponent <PE_Powerup>().powerupType = this.powerupType;

            // Kill Self
            PhysEngine.objs.Remove(this.GetComponent <PE_Obj>());
            Destroy(this.gameObject);
            break;
        }
    }
Esempio n. 6
0
    public void TimeStep(PE_Obj po, float dt)
    {
        if (po.still)
        {
            po.pos0 = po.pos1 = po.transform.position;
            return;
        }

        // Velocity
        po.vel0 = po.vel;
        Vector3 tAcc = po.acc;

        switch (po.grav)
        {
        case PE_GravType.constant:
            tAcc += gravity;
            break;
        }
        po.vel += tAcc * dt;

        /*if (po.vel.x==0) { // Special case when po.vel.x == 0
         *      if (po.vel.y > 0) {
         *              po.dir = PE_Dir.up;
         *      } else {
         *              po.dir = PE_Dir.down;
         *      }
         * } else if (po.vel.x>0 && po.vel.y>0) {
         *      po.dir = PE_Dir.upRight;
         * } else if (po.vel.x>0 && po.vel.y<=0) {
         *      po.dir = PE_Dir.downRight;
         * } else if (po.vel.x<0 && po.vel.y<=0) {
         *      po.dir = PE_Dir.downLeft;
         * } else if (po.vel.x<0 && po.vel.y>0) {
         *      po.dir = PE_Dir.upLeft;
         * }*/

        // Position
        po.pos1  = po.pos0 = po.transform.position;
        po.pos1 += po.vel * dt;
    }
Esempio n. 7
0
	public void TimeStep(PE_Obj po, float dt) {
		if (po.still) {
			po.pos0 = po.pos1 = po.transform.position;
			return;
		}

		// Velocity
		po.velRel = (po.pos1 - po.pos0) / dt;

		po.vel0 = po.vel;
		Vector3 tAcc = po.acc;
		switch (po.grav) {
		case PE_GravType.constant:
			tAcc += gravity;
			break;
		}
		po.vel += tAcc * dt;

		if (po.vel.x==0) { // Special case when po.vel.x == 0
			if (po.vel.y > 0) {
				po.dir = PE_Dir.up;
			} else {
				po.dir = PE_Dir.down;
			}
		} else if (po.vel.x>0 && po.vel.y>0) {
			po.dir = PE_Dir.upRight;
		} else if (po.vel.x>0 && po.vel.y<=0) {
			po.dir = PE_Dir.downRight;
		} else if (po.vel.x<0 && po.vel.y<=0) {
			po.dir = PE_Dir.downLeft;
		} else if (po.vel.x<0 && po.vel.y>0) {
			po.dir = PE_Dir.upLeft;
		}

		// Position
		po.pos0 = po.transform.position;
		po.pos1 += po.vel * dt;

	}
Esempio n. 8
0
    void OnTriggerExit(Collider other)
    {
        // Ignore collisions of still objects
        if (still)
        {
            return;
        }

        PE_Obj otherPEO = other.GetComponent <PE_Obj>();

        if (otherPEO == null || IgnoreCollision(other))
        {
            return;
        }

        // This sets ground to null if we fall off of the current ground
        // Jumping will also set ground to null
        if (ground == otherPEO)
        {
            ground = null;
        }
    }
Esempio n. 9
0
    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag != "Bike")
        {
            return;
        }

        PE_Obj otherPEO = other.GetComponent <PE_Obj> ();

        if (other.GetComponent <Bike> ().curState == Bike.State.IN_AIR)
        {
            return;
        }

        //no boosting if falling onto the ramp
        if (otherPEO.vel.y < -1f)
        {
            //print ("negative y");
            return;
        }
        //if moving too slow, no boost applied
        if (otherPEO.vel.y < minVel)
        {
            //print ("too slow");
            return;
        }
        //if holding left, boost will be applied as upward lift
        if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
        {
            otherPEO.vel.y += otherPEO.vel.x * power;
            otherPEO.vel.x -= otherPEO.vel.x * power / 4;
        }
        else
        {
            otherPEO.vel += boostGO.transform.right * otherPEO.vel.x * power;
            //print ("boosting");
        }
    }
Esempio n. 10
0
    bool OnScreen(PE_Obj po)
    {
        float vertExtent = Camera.main.camera.orthographicSize;
        float horzExtent = vertExtent * Screen.width / Screen.height;
        float left       = this.transform.position.x - horzExtent;
        float right      = this.transform.position.x + horzExtent;
        float top        = this.transform.position.y + vertExtent;
        float bottom     = this.transform.position.y - vertExtent;

        float objLeft   = po.transform.position.x - po.transform.lossyScale.x;
        float objRight  = po.transform.position.x + po.transform.lossyScale.x;
        float objBottom = po.transform.position.y - po.transform.lossyScale.y;
        float objTop    = po.transform.position.y + po.transform.lossyScale.y;

        if (objRight < right && objLeft > left && objBottom > bottom && objTop < top)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
Esempio n. 11
0
    override protected void ResolveCollisionWith(PE_Obj that)
    {
        switch (this.coll)
        {
        case PE_Collider.enemy:

            switch (that.coll)
            {
            case PE_Collider.platform:             // collide with platform
                Vector3 thatP    = that.transform.position;
                Vector3 newPos   = transform.position;
                float   boxSizeY = this.GetComponent <BoxCollider> ().size.y;
                newPos.y           = thatP.y + (this.transform.lossyScale.y * .5f * boxSizeY) + (that.transform.lossyScale.y / 2);
                transform.position = newPos;
                vel.y = 0;

                break;

            case PE_Collider.guy:             // collide with guy
                PE_Guy guy = that.GetComponent <PE_Guy> ();
                if (!guy.isDead)
                {
                    guy.death(false, that.transform.position);
                }
                break;

            case PE_Collider.friendlyBullet:             // collide with friendlyBullet
                PhysEngine.objs.Remove(that.GetComponent <PE_Obj>());
                Destroy(that.gameObject);
                PhysEngine.objs.Remove(this.GetComponent <PE_Obj>());
                Destroy(this.gameObject);
                break;
            }
            break;
        }
    }
Esempio n. 12
0
    public void TimeStep(PE_Obj po, float dt)
    {
        if (po.still)
        {
            po.pos0 = po.pos1 = po.transform.position;
            return;
        }

        // Velocity
        po.vel0 = po.vel;
        Vector3 tAcc = po.acc;

        switch (po.grav)
        {
        case PE_GravType.constant:
            tAcc += gravity;
            break;
        }
        po.vel += tAcc * dt;

        // Position
        po.pos1  = po.pos0 = po.transform.position;
        po.pos1 += po.vel * dt;
    }
Esempio n. 13
0
    void ResolveCollisionWith(PE_Obj that)
    {
        // Assumes that "that" is still
        //		Vector3 posFinal;
        posFinal = pos1;         // Sets a defaut value for posFinal

        switch (this.coll)
        {
        case PE_Collider.sphere:

            switch (that.coll)
            {
            case PE_Collider.sphere:
                // Sphere / Sphere collision
                float thisR, thatR, rad;
                // Note, this doesn't work with non-uniform or negative scales!
                thisR = Mathf.Max(this.transform.lossyScale.x, this.transform.lossyScale.y, this.transform.lossyScale.z) / 2;
                thatR = Mathf.Max(that.transform.lossyScale.x, that.transform.lossyScale.y, that.transform.lossyScale.z) / 2;
                rad   = thisR + thatR;

                Vector3 delta = pos1 - that.transform.position;
                delta.Normalize();
                delta *= rad;

                posFinal = that.transform.position + delta;
                break;
            }

            break;

        case PE_Collider.aabb:

            switch (that.coll)
            {
            case PE_Collider.aabb:
                // AABB / AABB collision
                // Axis-Aligned Bounding Box
                // With AABB collisions, we're usually concerned with corners and deciding which corner to consider when making comparisons.
                // I believe that this corner should be determined by looking at the velocity of the moving body (this one)

                // Vector3 a0, a1, b, delta, pU;
                // a0-moving corner last frame, a1-moving corner now, b-comparison corner on other object
                a0    = a1 = b = Vector3.zero;                   // Sets a default value to keep the compiler from complaining
                delta = pos1 - pos0;

                if (dir == PE_Dir.down)
                {
                    // If a0 was above b and a1 is below b resolve to be on top
                    a1    = pos1;
                    a1.y -= transform.collider.bounds.size.y / 2f;
                    a0    = a1 - delta;
                    b     = that.pos1;
                    b.y  += that.transform.collider.bounds.size.y / 2f;
                    if (PhysEngine.GEQ(a0.y, b.y) && b.y > a1.y)
                    {
                        posFinal.y += Mathf.Abs(a1.y - b.y);
                        // Handle vel
                        vel.y = 0;

                        if (ground == null)
                        {
                            ground = that;
                        }
                    }
                    break;                     // Exit this switch statement: switch (that.coll)
                }

                if (dir == PE_Dir.up)
                {
                    // If a0 was below b and a1 is above b resolve to be below
                    a1    = pos1;
                    a1.y += transform.collider.bounds.size.y / 2f;
                    a0    = a1 - delta;
                    b     = that.pos1;
                    b.y  -= that.transform.collider.bounds.size.y / 2f;
                    if (PhysEngine.LEQ(a0.y, b.y) && b.y < a1.y)
                    {
                        posFinal.y -= Mathf.Abs(a1.y - b.y);
                        // Handle vel
                        vel.y = 0;

                        break;                         // Exit this switch statement: switch (that.coll)
                    }
                }

                if (dir == PE_Dir.upRight)                   // Bottom, Left is the comparison corner
                {
                    a1    = pos1;
                    a1.x += transform.collider.bounds.size.x / 2f;
                    a1.y += transform.collider.bounds.size.y / 2f;
                    a0    = a1 - delta;
                    b     = that.pos1;
                    b.x  -= that.transform.collider.bounds.size.x / 2f;
                    b.y  -= that.transform.collider.bounds.size.y / 2f;
                }

                if (dir == PE_Dir.upLeft)                   // Bottom, Right is the comparison corner
                {
                    a1    = pos1;
                    a1.x -= transform.collider.bounds.size.x / 2f;
                    a1.y += transform.collider.bounds.size.y / 2f;
                    a0    = a1 - delta;
                    b     = that.pos1;
                    b.x  += that.transform.collider.bounds.size.x / 2f;
                    b.y  -= that.transform.collider.bounds.size.y / 2f;
                }

                if (dir == PE_Dir.downLeft)                   // Top, Right is the comparison corner
                {
                    a1    = pos1;
                    a1.x -= transform.collider.bounds.size.x / 2f;
                    a1.y -= transform.collider.bounds.size.y / 2f;
                    a0    = a1 - delta;
                    b     = that.pos1;
                    b.x  += that.transform.collider.bounds.size.x / 2f;
                    b.y  += that.transform.collider.bounds.size.y / 2f;
                }

                if (dir == PE_Dir.downRight)                   // Top, Left is the comparison corner
                {
                    a1    = pos1;
                    a1.x += transform.collider.bounds.size.x / 2f;
                    a1.y -= transform.collider.bounds.size.y / 2f;
                    a0    = a1 - delta;
                    b     = that.pos1;
                    b.x  -= that.transform.collider.bounds.size.x / 2f;
                    b.y  += that.transform.collider.bounds.size.y / 2f;
                }

                // In the x dimension, find how far along the line segment between a0 and a1 we need to go to encounter b
                float u = (b.x - a0.x) / (a1.x - a0.x);

                // Determine this point using linear interpolation (see the appendix of the book)
                pU = (1 - u) * a0 + u * a1;

                // Find distance we would have to offset in x or y
                float offsetX = Mathf.Abs(a1.x - b.x);
                float offsetY = Mathf.Abs(a1.y - b.y);

                // Use pU.y vs. b.y to tell which side of PE_Obj "that" PE_Obj "this" should be on
                switch (dir)
                {
                case PE_Dir.upRight:
                    if (pU.y > b.y || PhysEngine.EQ(u, 0))                       // hit the left side
                    {
                        posFinal.x -= offsetX;

                        // Handle vel
                        vel.x = 0;
                    }
                    else                         // hit the bottom
                    {
                        posFinal.y -= offsetY;

                        // Handle vel
                        vel.y = 0;
                    }
                    break;

                case PE_Dir.downRight:
                    if (pU.y < b.y || PhysEngine.EQ(u, 0))                       // hit the left side
                    {
                        posFinal.x -= offsetX;

                        // Handle vel
                        vel.x = 0;
                    }
                    else                         // hit the top
                    {
                        posFinal.y += offsetY;

                        // Handle vel
                        vel.y = 0;

                        if (ground == null)
                        {
                            ground = that;
                        }
                    }
                    break;

                case PE_Dir.upLeft:
                    if (pU.y > b.y || PhysEngine.EQ(u, 0))                       // hit the right side
                    {
                        posFinal.x += offsetX;

                        // Handle vel
                        vel.x = 0;
                    }
                    else                         // hit the bottom
                    {
                        posFinal.y -= offsetY;

                        // Handle vel
                        vel.y = 0;
                    }
                    break;

                case PE_Dir.downLeft:
                    if (pU.y < b.y || PhysEngine.EQ(u, 0))                       // hit the right side
                    {
                        posFinal.x += offsetX;

                        // Handle vel
                        vel.x = 0;
                    }
                    else                         // hit the top
                    {
                        posFinal.y += offsetY;

                        // Handle vel
                        vel.y = 0;

                        if (ground == null)
                        {
                            ground = that;
                        }
                    }
                    break;
                }

                break;
            }

            break;
        }

        transform.position = pos1 = posFinal;
    }
Esempio n. 14
0
	void ResolveCollisionWith(PE_Obj that) {
		
		// Assumes that "that" is still
		//		Vector3 posFinal;
		posFinal = pos1; // Sets a defaut value for posFinal
		
		switch (this.coll) {
		case PE_Collider.sphere:
			
			switch (that.coll) {
			case PE_Collider.sphere:
				// Sphere / Sphere collision
				float thisR, thatR, rad;
				// Note, this doesn't work with non-uniform or negative scales!
				thisR = Mathf.Max( this.transform.lossyScale.x, this.transform.lossyScale.y, this.transform.lossyScale.z ) / 2;
				thatR = Mathf.Max( that.transform.lossyScale.x, that.transform.lossyScale.y, that.transform.lossyScale.z ) / 2;
				rad = thisR + thatR;
				
				Vector3 delta = pos1 - that.transform.position;
				delta.Normalize();
				delta *= rad;
				
				posFinal = that.transform.position + delta;
				break;
			}
			
			break;
			
		case PE_Collider.aabb:
			
			switch (that.coll) {
			case PE_Collider.aabb:
				// AABB / AABB collision
				// Axis-Aligned Bounding Box
				// With AABB collisions, we're usually concerned with corners and deciding which corner to consider when making comparisons.
				// I believe that this corner should be determined by looking at the velocity of the moving body (this one)
				
				// Vector3 a0, a1, b, delta, pU; 
				// a0-moving corner last frame, a1-moving corner now, b-comparison corner on other object
				a0 = a1 = b = Vector3.zero;	 // Sets a default value to keep the compiler from complaining
				delta = pos1 - pos0;
				
				if (dir == PE_Dir.down) {
					// If a0 was above b and a1 is below b resolve to be on top
					a1 = pos1;
					a1.y -= transform.collider.bounds.size.y/2f;
					a0 = a1 - delta;
					b = that.pos1;
					b.y += that.transform.collider.bounds.size.y/2f;
					if ( PhysEngine.GEQ( a0.y, b.y ) && b.y > a1.y) {
						posFinal.y += Mathf.Abs( a1.y - b.y );
						// Handle vel
						vel.y = 0;
						
						if (ground == null) {
							ground = that;
						} 
					}
					break; // Exit this switch statement: switch (that.coll)
				}
				
				if (dir == PE_Dir.up) {
					// If a0 was below b and a1 is above b resolve to be below
					a1 = pos1;
					a1.y += transform.collider.bounds.size.y/2f;
					a0 = a1 - delta;
					b = that.pos1;
					b.y -= that.transform.collider.bounds.size.y/2f;
					if ( PhysEngine.LEQ( a0.y, b.y ) && b.y < a1.y) {
						posFinal.y -= Mathf.Abs( a1.y - b.y );
						// Handle vel
						vel.y = 0;
						
						break; // Exit this switch statement: switch (that.coll)
					}
				}
				
				if (dir == PE_Dir.upRight) { // Bottom, Left is the comparison corner
					a1 = pos1;
					a1.x += transform.collider.bounds.size.x/2f;
					a1.y += transform.collider.bounds.size.y/2f;
					a0 = a1 - delta;
					b = that.pos1;
					b.x -= that.transform.collider.bounds.size.x/2f;
					b.y -= that.transform.collider.bounds.size.y/2f;
				}
				
				if (dir == PE_Dir.upLeft) { // Bottom, Right is the comparison corner
					a1 = pos1;
					a1.x -= transform.collider.bounds.size.x/2f;
					a1.y += transform.collider.bounds.size.y/2f;
					a0 = a1 - delta;
					b = that.pos1;
					b.x += that.transform.collider.bounds.size.x/2f;
					b.y -= that.transform.collider.bounds.size.y/2f;
				}
				
				if (dir == PE_Dir.downLeft) { // Top, Right is the comparison corner
					a1 = pos1;
					a1.x -= transform.collider.bounds.size.x/2f;
					a1.y -= transform.collider.bounds.size.y/2f;
					a0 = a1 - delta;
					b = that.pos1;
					b.x += that.transform.collider.bounds.size.x/2f;
					b.y += that.transform.collider.bounds.size.y/2f;
				}
				
				if (dir == PE_Dir.downRight) { // Top, Left is the comparison corner
					a1 = pos1;
					a1.x += transform.collider.bounds.size.x/2f;
					a1.y -= transform.collider.bounds.size.y/2f;
					a0 = a1 - delta;
					b = that.pos1;
					b.x -= that.transform.collider.bounds.size.x/2f;
					b.y += that.transform.collider.bounds.size.y/2f;
				}
				
				// In the x dimension, find how far along the line segment between a0 and a1 we need to go to encounter b
				float u = (b.x - a0.x) / (a1.x - a0.x);
				
				// Determine this point using linear interpolation (see the appendix of the book)
				pU = (1-u)*a0 + u*a1;
				
				// Find distance we would have to offset in x or y
				float offsetX = Mathf.Abs(a1.x - b.x);
				float offsetY = Mathf.Abs(a1.y - b.y);
				
				// Use pU.y vs. b.y to tell which side of PE_Obj "that" PE_Obj "this" should be on
				switch (dir) {
				case PE_Dir.upRight:
					if (pU.y > b.y || PhysEngine.EQ(u, 0)) { // hit the left side
						posFinal.x -= offsetX;
						
						// Handle vel
						vel.x = 0;
						
					} else { // hit the bottom
						posFinal.y -= offsetY;
						
						// Handle vel
						vel.y = 0;
						
					}
					break;
					
				case PE_Dir.downRight:
					if (pU.y < b.y || PhysEngine.EQ(u, 0)) { // hit the left side
						posFinal.x -= offsetX;
						
						// Handle vel
						vel.x = 0;
						
					} else { // hit the top
						posFinal.y += offsetY;
						
						// Handle vel
						vel.y = 0;
						
						if (ground == null) ground = that;
					}
					break;
					
				case PE_Dir.upLeft:
					if (pU.y > b.y || PhysEngine.EQ(u, 0)) { // hit the right side
						posFinal.x += offsetX;
						
						// Handle vel
						vel.x = 0;
						
					} else { // hit the bottom
						posFinal.y -= offsetY;
						
						// Handle vel
						vel.y = 0;
						
					}
					break;
					
				case PE_Dir.downLeft:
					if (pU.y < b.y || PhysEngine.EQ(u, 0)) { // hit the right side
						posFinal.x += offsetX;
						
						// Handle vel
						vel.x = 0;
						
					} else { // hit the top
						posFinal.y += offsetY;
						
						// Handle vel
						vel.y = 0;
						
						if (ground == null) ground = that;
					}
					break;
				}
				
				break;
			}
			
			break;
		}
		
		transform.position = pos1 = posFinal;
	}
Esempio n. 15
0
    override protected void ResolveCollisionWith(PE_Obj that)
    {
        switch (that.coll)
        {
        case PE_Collider.platform:
            // In Progress
            Vector3 thatP = that.transform.position;
            Vector3 delta = (pos1 - this.transform.lossyScale / 2) - (thatP - that.transform.lossyScale / 2);
            if (isInWater)
            {
                if (!isClimbing)
                {
                    climbTimer = Time.time;
                    isClimbing = true;
                }
                Vector3 newPos = transform.position;

                //Take a quarter of a second to climb up ledge
                if (Time.time > climbTimer + .15f)
                {
                    isInWater  = false;
                    isClimbing = false;
                    RepositionToTop(that);
                    break;
                }
                newPos = transform.position;
                if (transform.position.x > thatP.x)
                {
                    newPos.x = thatP.x + (that.transform.lossyScale.x / 2);
                }
                else if (transform.position.x < thatP.x)
                {
                    newPos.x = thatP.x - (that.transform.lossyScale.x / 2);
                }
                this.transform.position = newPos;
            }
            else if (delta.y >= 0)                                         // Top
            {
                if (vel.y <= 0)
                {
                    // Landed!
                    if (isInAir)
                    {
                        isInAir = false;
                        makeNotJump();
                    }
                    if (fD == FacingDir.down)
                    {
                        fD = lastDir;
                    }
                    RepositionToTop(that);
                }
            }
            break;


        //TODO Change this to handle sprites properly
        case PE_Collider.water:
            //If you are in the water then you can no longer jump
            isInWater = true;
            if (isInAir)
            {
                isInAir = false;
                makeNotJump();
            }

            RepositionToTop(that);
            break;

        case PE_Collider.enemyBullet:
            if (!isDead)
            {
                death(false, transform.position);
            }
            break;

        case PE_Collider.powerup:
            PowerupType pt = that.GetComponent <PE_Powerup>().powerupType;
            print("You got a powerup of type: " + pt);
            switch (pt)
            {
            case PowerupType.rapidFire:
                fireRate  *= .85f;
                burstRate *= .85f;
                break;

            case PowerupType.machineGun:
                gunType   = GunType.machineGun;
                fireRate  = .12f;
                burstRate = .15f;
                break;

            case PowerupType.spreadGun:
                gunType   = GunType.spreadGun;
                fireRate  = normFireRate;
                burstRate = normBurstRate;
                break;

            case PowerupType.laser:
                gunType   = GunType.laser;
                fireRate  = 1f;
                burstRate = 1f;
                break;

            case PowerupType.flame:
                gunType   = GunType.flame;
                fireRate  = .3f;
                burstRate = 1f;
                break;
            }
            // Remove powerup from game
            PhysEngine.objs.Remove(that.GetComponent <PE_Obj>());
            Destroy(that.gameObject);
            break;
        }
    }
Esempio n. 16
0
 // Use this for initialization
 void Start()
 {
     peo        = GetComponent <PE_Obj>();
     physEngine = Camera.main.GetComponent <PhysEngine>();
 }
Esempio n. 17
0
	// Use this for initialization
	void Start () {
		peo = this.GetComponent<PE_Obj>();
		player_peo = player.GetComponent<PE_Obj>();
		//peo.still = true;
	}
Esempio n. 18
0
    void ResolveCollisionWith(PE_Obj that)
    {
        // Assumes that "that" is still
        Vector3 posFinal = pos1;         // Sets a defaut value for posFinal
        Bike    thisBike = this.GetComponent <Bike>();

        switch (this.coll)
        {
        case PE_Collider.sphere:

            switch (that.coll)
            {
            case PE_Collider.sphere:
                // Sphere / Sphere collision
                float thisR, thatR, rad;
                // Note, this doesn't work with non-uniform or negative scales!
                thisR = Mathf.Max(this.transform.lossyScale.x, this.transform.lossyScale.y, this.transform.lossyScale.z) / 2;
                thatR = Mathf.Max(that.transform.lossyScale.x, that.transform.lossyScale.y, that.transform.lossyScale.z) / 2;
                rad   = thisR + thatR;

                Vector3 delta = pos1 - that.transform.position;
                delta.Normalize();
                delta *= rad;

                posFinal = that.transform.position + delta;
                break;
            }

            break;

        case PE_Collider.aabb:
            bool  bounce    = false;
            float bounceVel = -vel.y * bouncePower;
            bounceVel = bounceVel > bounceFloorVel? bounceVel:bounceFloorVel;
            if (thisBike.curState == Bike.State.IN_AIR && vel.y < 0f && Mathf.Abs(vel.y) > minBounceVel)
            {
                float myAngle = Vector3.Angle(transform.up, that.transform.up);
                //if (myAngle > 180f)
                //myAngle = 360f - myAngle;
                //float angleDiff = Mathf.Abs( that.transform.rotation.z - myAngle);
                print(myAngle);
                if (myAngle > landingEase)
                {
                    bounce = true;
                }
            }
            switch (that.coll)
            {
            case PE_Collider.aabb:

                thisBike.curState = Bike.State.ON_GROUND;

                // AABB / AABB collision
                float eX1, eY1, eX2, eY2, dX, dY, eX0, eY0;

                Vector3 overlap = Vector3.zero;
                Vector3 thatP   = that.transform.position;
                Vector3 delta   = pos1 - thatP;

                eX0 = pos0.x - this.transform.lossyScale.x / 2;
                eY0 = pos0.y - this.transform.lossyScale.y / 2;
                eX1 = pos1.x - this.transform.lossyScale.x / 2;
                eY1 = pos1.y - this.transform.lossyScale.y / 2;
                eX2 = thatP.x + that.transform.lossyScale.x / 2;
                eY2 = thatP.y + that.transform.lossyScale.y / 2;


                // Distance traveled this step
                dX = eX1 - eX0;
                dY = eY1 - eY0;
                float uX = 1;
                float uY = 1;
                if (eX1 < eX2)
                {
                    // Overlap in X direction
                    uX = 1 - (eX2 - eX1) / (eX0 - eX1);
                }
                if (eY1 < eY2)
                {
                    // Overlap in Y direction
                    uY = 1 - (eY2 - eY1) / (eY0 - eY1);
                }
                // Find Overlaps (positive is an overlap, negative
                //overlap.x = uX;
                overlap.y = uY;

                if (overlap.y >= 0)
                {
                    //print ("asdf");
                    Vector3 moved = transform.position;
                    moved.y           += (eY2 - eY1);
                    transform.position = moved;
                    if (vel.y < 0)
                    {
                        vel.y = 0;
                    }
                }

                break;


            case PE_Collider.plane:
                thisBike.curState = Bike.State.ON_RAMP;

                GameObject rampGO = that.gameObject;
                if (rampGO.tag == "Ramp" || rampGO.tag == "LapRamp")
                {
                    grav = PE_GravType.none;
                }

                Vector3 cornerPos = this.gameObject.transform.position;
                //check which corner has collided
                if (rampGO.transform.rotation.z > 0)
                {
                    cornerPos.x += this.transform.lossyScale.x / 2;
                }
                else
                {
                    cornerPos.x -= this.transform.lossyScale.x / 2;
                }
                cornerPos.y -= this.transform.lossyScale.y / 2;
                Vector3 rampVec = rampGO.transform.right;
                if (rampGO.transform.rotation.z != 0)
                {
                    vel = rampVec * vel.magnitude;
                }
                else
                {
                    if (vel.y < 0)
                    {
                        vel = rampVec * vel.x;
                    }
                }
                //vel = rampVec * vel.magnitude;
                //acc = rampVec * acc.magnitude;

                //RayCasting from corner toward plane to get depth of penetration
                Ray cornerRay = new Ray(cornerPos, rampGO.transform.up);
                Debug.DrawRay(cornerPos, rampGO.transform.up * 100f);
                RaycastHit hit = new RaycastHit();
                if (!Physics.Raycast(cornerRay, out hit, 10f))
                {
                    return;
                }

                /*float dist = Mathf.Sqrt(transform.lossyScale.x*transform.lossyScale.x + transform.lossyScale.y*transform.lossyScale.y);
                 * dist -= hit.distance;*/
                Vector3 temp = transform.position;
                temp += rampGO.transform.up * (hit.distance);
                transform.position = temp;
                lastRampAngle      = rampGO.transform.eulerAngles;
                break;
            }
            if (bounce)
            {
                print("bouncing");
                vel.y             = bounceVel;
                vel.x            -= vel.x * bounceSlow;
                thisBike.curState = Bike.State.IN_AIR;
            }
            break;
        }
    }
Esempio n. 19
0
	// Use this for initialization
	void Start () {
        peo = GetComponent<PE_Obj>();
		peo.vel = new Vector2 (velocity*peo.vel.x, velocity*peo.vel.y);
	}
Esempio n. 20
0
 protected virtual void ResolveCollisionWith(PE_Obj that)
 {
 }
Esempio n. 21
0
 // Use this for initialization
 void Start()
 {
     peo        = this.GetComponent <PE_Obj>();
     player_peo = player.GetComponent <PE_Obj>();
     //peo.still = true;
 }
Esempio n. 22
0
 // Use this for initialization
 void Start()
 {
     peo     = GetComponent <PE_Obj>();
     peo.vel = new Vector2(velocity * peo.vel.x, velocity * peo.vel.y);
 }
Esempio n. 23
0
    void ResolveCollisionWith(PE_Obj that)
    {
        // Assumes that "that" is still

        switch (this.coll)
        {
        case PE_Collider.sphere:

            switch (that.coll)
            {
            case PE_Collider.sphere:
                // Sphere / Sphere collision
                float thisR, thatR, rad;
                // Note, this doesn't work with non-uniform or negative scales!
                thisR = Mathf.Max(this.transform.lossyScale.x, this.transform.lossyScale.y, this.transform.lossyScale.z) / 2;
                thatR = Mathf.Max(that.transform.lossyScale.x, that.transform.lossyScale.y, that.transform.lossyScale.z) / 2;
                rad   = thisR + thatR;

                Vector3 delta = pos1 - that.transform.position;
                delta.Normalize();
                delta *= rad;

                transform.position = that.transform.position + delta;
                break;
            }

            break;

        case PE_Collider.aabb:

            switch (that.coll)
            {
            case PE_Collider.aabb:


                // AABB / AABB collision
                float eX1, eY1, eX2, eY2, dX, dY, eX0, eY0;

                Vector3 overlap = Vector3.zero;
                thatP = that.transform.position;
                delta = pos1 - thatP;
                if (delta.x >= 0 && delta.y >= 0)                   // Top, Right
                // Get the edges that we're concerned with
                {
                    eX0 = pos0.x - this.transform.lossyScale.x / 2;
                    eY0 = pos0.y - this.transform.lossyScale.y / 2;
                    eX1 = pos1.x - this.transform.lossyScale.x / 2;
                    eY1 = pos1.y - this.transform.lossyScale.y / 2;
                    eX2 = thatP.x + that.transform.lossyScale.x / 2;
                    eY2 = thatP.y + that.transform.lossyScale.y / 2;

                    float mThis = (eY0 - eY1) / (eX0 - eX1);
                    float mThat = (eY0 - eY2) / (eX0 - eX2);

                    if ((mThis < mThat) || ((eX0 == eX1) && (mThat <= 0) && (eX0 != eX2)))                      // land on top
                    {
                        float dist = this.transform.lossyScale.y / 2 + that.transform.lossyScale.y / 2;
                        vel.y = 0;
                        Vector3 pos = new Vector3(this.transform.position.x, that.transform.position.y + dist, this.transform.position.z);
                        this.transform.position = pos;
                    }
                    else                       // hit the right side
                    {
                        float dist = this.transform.lossyScale.x / 2 + that.transform.lossyScale.x / 2;
                        vel.x = 0;
                        Vector3 pos = new Vector3(that.transform.position.x + dist, this.transform.position.y, this.transform.position.z);
                        this.transform.position = pos;
                    }
                    // Distance traveled this step
//					dX = eX1-eX0;
//					dY = eY1-eY0;
//					float uX = 1;
//					float uY = 1;
//					if (eX1 < eX2) { // Overlap in X direction
//						uX = 1 - (eX2-eX1) / (eX0-eX1);
//
//					}
//					if (eY1 < eY2) { // Overlap in Y direction
//						uY = 1 - (eY2-eY1) / (eY0-eY1);
//
//					}
                    // Find Overlaps (positive is an overlap, negative
                    // overlap.x =
                }
                else if (delta.x >= 0 && delta.y < 0)                     // Bottom, Right
                {
                    eX0 = pos0.x - this.transform.lossyScale.x / 2;
                    eY0 = pos0.y + this.transform.lossyScale.y / 2;
                    eX1 = pos1.x - this.transform.lossyScale.x / 2;
                    eY1 = pos1.y + this.transform.lossyScale.y / 2;
                    eX2 = thatP.x + that.transform.lossyScale.x / 2;
                    eY2 = thatP.y - that.transform.lossyScale.y / 2;

                    float mThis = (eY0 - eY1) / (eX0 - eX1);
                    float mThat = (eY0 - eY2) / (eX0 - eX2);

                    if ((mThis > mThat) || ((eX0 == eX1) && (mThat >= 0) && (eX0 != eX2)))                      // hit the bottom
                    {
                        float dist = this.transform.lossyScale.y / 2 + that.transform.lossyScale.y / 2;
                        vel.y = 0;
                        Vector3 pos = new Vector3(this.transform.position.x, that.transform.position.y - dist, this.transform.position.z);
                        this.transform.position = pos;
                    }
                    else                       // hit the right side
                    {
                        float dist = this.transform.lossyScale.x / 2 + that.transform.lossyScale.x / 2;
                        vel.x = 0;
                        Vector3 pos = new Vector3(that.transform.position.x + dist, this.transform.position.y, this.transform.position.z);
                        this.transform.position = pos;
                    }
                }
                else if (delta.x < 0 && delta.y < 0)                     // Bottom, Left
                {
                    eX0 = pos0.x + this.transform.lossyScale.x / 2;
                    eY0 = pos0.y + this.transform.lossyScale.y / 2;
                    eX1 = pos1.x + this.transform.lossyScale.x / 2;
                    eY1 = pos1.y + this.transform.lossyScale.y / 2;
                    eX2 = thatP.x - that.transform.lossyScale.x / 2;
                    eY2 = thatP.y - that.transform.lossyScale.y / 2;

                    float mThis = (eY0 - eY1) / (eX0 - eX1);
                    float mThat = (eY0 - eY2) / (eX0 - eX2);

                    if ((mThis < mThat) || ((eX0 == eX1) && (mThat <= 0) && (eX0 != eX2)))                      // hit the bottom
                    {
                        float dist = this.transform.lossyScale.y / 2 + that.transform.lossyScale.y / 2;
                        vel.y = 0;
                        Vector3 pos = new Vector3(this.transform.position.x, that.transform.position.y - dist, this.transform.position.z);
                        this.transform.position = pos;
                    }
                    else                       // hit the left side
                    {
                        float dist = this.transform.lossyScale.x / 2 + that.transform.lossyScale.x / 2;
                        vel.x = 0;
                        Vector3 pos = new Vector3(that.transform.position.x - dist, this.transform.position.y, this.transform.position.z);
                        this.transform.position = pos;
                    }
                }
                else if (delta.x < 0 && delta.y >= 0)                     // Top, Left
                {
                    eX0 = pos0.x + this.transform.lossyScale.x / 2;
                    eY0 = pos0.y - this.transform.lossyScale.y / 2;
                    eX1 = pos1.x + this.transform.lossyScale.x / 2;
                    eY1 = pos1.y - this.transform.lossyScale.y / 2;
                    eX2 = thatP.x - that.transform.lossyScale.x / 2;
                    eY2 = thatP.y + that.transform.lossyScale.y / 2;

                    float mThis = (eY0 - eY1) / (eX0 - eX1);
                    float mThat = (eY0 - eY2) / (eX0 - eX2);

                    if ((mThis > mThat) || ((eX0 == eX1) && (mThat <= 0) && (eX0 != eX2)))                      // land on top
                    {
                        float dist = this.transform.lossyScale.y / 2 + that.transform.lossyScale.y / 2;
                        vel.y = 0;
                        Vector3 pos = new Vector3(this.transform.position.x, that.transform.position.y + dist, this.transform.position.z);
                        this.transform.position = pos;
                    }
                    else                       // hit the left side
                    {
                        float dist = this.transform.lossyScale.x / 2 + that.transform.lossyScale.x / 2;
                        vel.x = 0;
                        Vector3 pos = new Vector3(that.transform.position.x - dist, this.transform.position.y, this.transform.position.z);
                        this.transform.position = pos;
                    }
                }


                break;
            }

            break;
        }
    }
Esempio n. 24
0
	void OnTriggerExit(Collider other) {
		// Ignore collisions of still objects
		if (still) return;
		
		PE_Obj otherPEO = other.GetComponent<PE_Obj>();
		if (otherPEO == null || IgnoreCollision(other)) return;
		
		// This sets ground to null if we fall off of the current ground
		// Jumping will also set ground to null
		if (ground == otherPEO) {
			ground = null;
		}
	}
Esempio n. 25
0
	// Use this for initialization
	void Start () {
		peo = GetComponent<PE_Obj>();
		physEngine = Camera.main.GetComponent<PhysEngine>();
	}
Esempio n. 26
0
	public Vector3 a0, a1, b, delta, pU, posFinal; // a0-moving corner last frame, a1-moving corner now, b-comparison corner on other object

	void ResolveCollisionWithEnemy(PE_Obj that) {
		
		// Assumes that "that" is still
		//		Vector3 posFinal;
		posFinal = pos1; // Sets a defaut value for posFinal

		if (that.transform.position.x >= transform.position.x) { // Hit on the right
			acc.x = -120;
		} else { // Hit on the left
			acc.x = 120;
		}

		if(that.transform.position.y > transform.position.y + 1){
			vel.y = -4;
		} else {
			vel.y = 4;
		}
		
		transform.position = pos1 = posFinal;
	}
Esempio n. 27
0
    void Update()
    {
        if (invulnerable && Time.time > invuln_until)
        {
            if (!GetComponent <PE_Controller>().jeremyMode)
            {
                invulnerable = false;
            }
            GetComponent <SpriteRenderer>().color = Color.white;
            GetComponent <PE_Obj>().acc.x         = 0;
        }



        if (transform.position.y > 12.5 && gravitySwap)
        {
            physEngine.gravity = new Vector3(0, 1f, 0);
            GetComponent <PE_Controller>().maxSpeed = new Vector2(2.2f, 1.2f);
            GetComponent <PE_Controller>().floating = true;
        }
        else if (gravitySwap)
        {
            physEngine.gravity = new Vector3(0, -9.8f, 0);
            GetComponent <PE_Controller>().maxSpeed = new Vector2(10f, 15f);
            GetComponent <PE_Controller>().floating = false;
        }

        if (Input.GetKey(KeyCode.G))
        {
            invulnerable = true;
            invuln_until = float.MaxValue;
            GetComponent <PE_Controller>().jeremyMode = true;
        }

        if (Input.GetButton("Fire") && Time.time > nextFire && !crouching)
        {
            nextFire = Time.time + fireRate;

            GameObject clone;
            if (Input.GetAxis("Vertical") > 0)
            {
                Vector3 bullet_pos = new Vector3(
                    transform.position.x,
                    transform.position.y + BulletOffset_y_vertical,
                    transform.position.z);
                clone = Instantiate(projectile, bullet_pos, transform.rotation) as GameObject;
                PE_Obj pe = clone.GetComponent <PE_Obj> ();
                pe.vel = new Vector3(0, 1, 0);
            }
            else
            {
                Vector3 bullet_pos = new Vector3(
                    transform.position.x + (BulletOffset_x * transform.localScale.x),
                    transform.position.y + BulletOffset_y,
                    transform.position.z);
                clone = Instantiate(projectile, bullet_pos, transform.rotation) as GameObject;
                PE_Obj pe = clone.GetComponent <PE_Obj> ();
                pe.vel = new Vector3(transform.localScale.x, 0, 0);
            }

            clone.layer = LayerMask.NameToLayer("Player Bullet");
            Bullet bullet = clone.GetComponent <Bullet>();
            bullet.damage      = BulletDamage;
            bullet.maxDistance = BulletRange;
        }
    }
Esempio n. 28
0
    void FixedUpdate()
    {
        if (!raceStarted)
        {
            return;
        }

        PE_Obj bikePEO = this.GetComponent <PE_Obj> ();

        //push the bike forward (cheat) if it gets stuck
        //leave in the game as a "god mode"
        if (Input.GetKey(KeyCode.I))
        {
            Vector3 tempPos = bikePEO.transform.position;
            tempPos.x += 2;
            bikePEO.transform.position = tempPos;
        }

        float accX = 0f;
        float velZ = 0f;

        switch (curAccIn)
        {
        case AccInput.FAST:
            accX = fastAcc;
            break;

        case AccInput.SLOW:
            accX = slowAcc;
            break;

        case AccInput.NONE:
            accX = constDecel;
            break;
        }

        switch (curDirIn)
        {
        case DirInput.DOWN:
            velZ = down;
            break;

        case DirInput.UP:
            velZ = up;
            break;

        case DirInput.NONE:
            velZ = stay;
            break;
        }

        //crashing
        //implement ramp crashes: move it past the ramp to the ground immediately after the ramp
        if (crashed)
        {
            crash();
        }
        else if (overheated)
        {
            overheat();
        }
        else
        {
            if (curState == State.ON_GROUND || curState == State.ON_RAMP)
            {
                bikePEO.UpdateAccel(new Vector3(accX, 0, 0));
            }

            //automatically slow down if over max speed for any reason (after a jump boost)
            if (bikePEO.vel.x > maxSpeed && curState != State.IN_AIR)
            {
                bikePEO.UpdateAccel(new Vector3(constDecel, 0, 0));
            }
            else if (bikePEO.vel.x > maxSpeed && curState == State.IN_AIR)
            {
                bikePEO.UpdateAccel(new Vector3(airDecel, 0, 0));
            }
            else if (bikePEO.vel.x <= maxAirSpeed && curState == State.IN_AIR)
            {
                bikePEO.UpdateAccel(new Vector3(0, 0, 0));
            }
            else if (bikePEO.vel.x == maxSpeed && curAccIn != AccInput.NONE && curState != State.IN_AIR)
            {
                bikePEO.UpdateAccel(new Vector3(0, 0, 0));
            }

            if (bikePEO.vel.x <= 0 && curAccIn == AccInput.NONE)
            {
                bikePEO.UpdateAccel(new Vector3(0, 0, 0));
                bikePEO.UpdateVel(new Vector3(0, bikePEO.vel.y, bikePEO.vel.z));
            }

            if (jetOn)
            {
                //this applies jet power directly up
                //bikePEO.UpdateAccel(new Vector3(bikePEO.acc.x, bikePEO.acc.y + jetPower, bikePEO.acc.z));
                //this applies jet power toward bottom of the bike
                bikePEO.acc += transform.up * jetPower;
                curState     = State.IN_AIR;
            }

            //lanes
            //this needs to only happen on ground (or full width ramp)
            if (curState == State.ON_GROUND)
            {
                if (curDirIn == DirInput.UP)
                {
                    bikePEO.UpdateVel(new Vector3(bikePEO.vel.x, bikePEO.vel.y, velZ));
                    prevDirIn = DirInput.UP;
                }
                else if (curDirIn == DirInput.DOWN)
                {
                    bikePEO.UpdateVel(new Vector3(bikePEO.vel.x, bikePEO.vel.y, velZ));
                    prevDirIn = DirInput.DOWN;
                }
                else
                {
                    if (bikePEO.transform.position.z > 2.25)
                    {
                        //set bike position to go down until it reaches 2.25
                        newPosition = new Vector3(bikePEO.transform.position.x, bikePEO.transform.position.y, 2.25f);
                        bikePEO.transform.position = Vector3.Lerp(bikePEO.transform.position, newPosition, lerpTime);
                        bikePEO.UpdateVel(new Vector3(bikePEO.vel.x, bikePEO.vel.y, 0f));
                    }
                    else if (bikePEO.transform.position.z <= 2.25 && bikePEO.transform.position.z > .75f)
                    {
                        if (prevDirIn == DirInput.UP)
                        {
                            //set bike position to go up until it reaches 2.25
                            newPosition = new Vector3(bikePEO.transform.position.x, bikePEO.transform.position.y, 2.25f);
                        }
                        else if (prevDirIn == DirInput.DOWN)
                        {
                            //go down to .75
                            newPosition = new Vector3(bikePEO.transform.position.x, bikePEO.transform.position.y, .75f);
                        }
                        bikePEO.transform.position = Vector3.Lerp(bikePEO.transform.position, newPosition, lerpTime);
                        bikePEO.UpdateVel(new Vector3(bikePEO.vel.x, bikePEO.vel.y, 0f));
                    }
                    else if (bikePEO.transform.position.z <= .75f && bikePEO.transform.position.z > -.75f)
                    {
                        if (prevDirIn == DirInput.UP)
                        {
                            newPosition = new Vector3(bikePEO.transform.position.x, bikePEO.transform.position.y, .75f);
                        }
                        else if (prevDirIn == DirInput.DOWN)
                        {
                            newPosition = new Vector3(bikePEO.transform.position.x, bikePEO.transform.position.y, -.75f);
                        }
                        bikePEO.transform.position = Vector3.Lerp(bikePEO.transform.position, newPosition, lerpTime);
                        bikePEO.UpdateVel(new Vector3(bikePEO.vel.x, bikePEO.vel.y, 0f));
                    }
                    else if (bikePEO.transform.position.z <= -.75f && bikePEO.transform.position.z > -2.25f)
                    {
                        if (prevDirIn == DirInput.UP)
                        {
                            newPosition = new Vector3(bikePEO.transform.position.x, bikePEO.transform.position.y, -.75f);
                        }
                        else if (prevDirIn == DirInput.DOWN)
                        {
                            newPosition = new Vector3(bikePEO.transform.position.x, bikePEO.transform.position.y, -2.25f);
                        }
                        bikePEO.transform.position = Vector3.Lerp(bikePEO.transform.position, newPosition, lerpTime);
                        bikePEO.UpdateVel(new Vector3(bikePEO.vel.x, bikePEO.vel.y, 0f));
                    }
                    else
                    {
                        newPosition = new Vector3(bikePEO.transform.position.x, bikePEO.transform.position.y, -2.25f);
                        bikePEO.transform.position = Vector3.Lerp(bikePEO.transform.position, newPosition, lerpTime);
                        bikePEO.UpdateVel(new Vector3(bikePEO.vel.x, bikePEO.vel.y, 0f));
                    }
                }
            }

            //wheelie
            if (curState == State.ON_GROUND)
            {
                if (curRotIn == RotInput.LEFT && bikePEO.transform.eulerAngles.z <= maxAngle + 25 && (Input.GetKey(KeyCode.X) || Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.Period) || Input.GetKey(KeyCode.Comma)))
                {
                    bikePEO.transform.Rotate(Vector3.forward * (rotSpeed * Time.deltaTime));
                }
                else if ((bikePEO.transform.eulerAngles.z >= maxAngle + 25 && bikePEO.transform.eulerAngles.z <= maxAngle + 25 + 4) || (bikePEO.transform.eulerAngles.z <= 360 - maxAngle && bikePEO.transform.eulerAngles.z >= 360 - maxAngle - 5))
                {
                    //print (bikePEO.transform.eulerAngles.z);
                    crashed = true;
                    curTime = Time.time;
                }
                else if (bikePEO.transform.eulerAngles.z >= maxAngle + 25 + 5)
                {
                    bikePEO.transform.Rotate(Vector3.forward * (rotSpeed * Time.deltaTime));
                }
                else if (bikePEO.transform.eulerAngles.z >= 0)
                {
                    bikePEO.transform.Rotate(Vector3.back * (rotSpeed * Time.deltaTime));
                }
            }

            //in air rotation
            if (curState == State.IN_AIR)
            {
                if (bikePEO.transform.eulerAngles.z >= maxAngle - 1 && bikePEO.transform.eulerAngles.z < 180)
                {
                    Vector3 temp = bikePEO.transform.eulerAngles;
                    temp.z = maxAngle - 1;
                    bikePEO.transform.eulerAngles = temp;
                }

                if (bikePEO.transform.eulerAngles.z <= 360 - maxAngle && bikePEO.transform.eulerAngles.z > 180)
                {
                    Vector3 temp = bikePEO.transform.eulerAngles;
                    temp.z = 360 - maxAngle + 1;
                    bikePEO.transform.eulerAngles = temp;
                }

                if (bikePEO.transform.eulerAngles.z >= 360 - maxAngle || bikePEO.transform.eulerAngles.z <= maxAngle - 1)
                {
                    if (curRotIn == RotInput.RIGHT)
                    {
                        bikePEO.transform.Rotate(Vector3.back * (rotSpeed * Time.deltaTime));
                    }
                    else if (curRotIn == RotInput.LEFT)
                    {
                        bikePEO.transform.Rotate(Vector3.forward * (rotSpeed * Time.deltaTime));
                    }
                }
            }

            if (curState == State.ON_RAMP)
            {
                if ((bikePEO.transform.eulerAngles.z >= maxAngle && bikePEO.transform.eulerAngles.z <= maxAngle + 4) || (bikePEO.transform.eulerAngles.z <= 360 - maxAngle && bikePEO.transform.eulerAngles.z >= 360 - maxAngle - 5))
                {
                    Vector3 tempPos = bikePEO.transform.position;
                    tempPos.x += 2;
                    tempPos.y += 3;
                    bikePEO.transform.position = tempPos;
                    crashed = true;
                    curTime = Time.time;
                }

                //rotation set to 0
                Vector3 tempRot = Vector3.zero;
                bikePEO.transform.eulerAngles = tempRot;
            }
        }
    }