Пример #1
0
	public bool allows(relationToOther relation){
		if (relation == relationToOther.TOLEFT){
			return allowLeft;
		}
		if (relation == relationToOther.TORIGHT){
			return allowRight;
		}
		return true;
	}
Пример #2
0
	void exitSwitchOnRelation(relationToOther relation, Collider other){
		switch(relation){
		case relationToOther.ONTOP:
			if (!GetComponent<PhysicsObject>().onGround) return;
			else if (onShroom) return;
			else if (isTouching(other) && inBounds(other)) return;
			else GetComponent<FallingObject>().fall();
			break;
		case relationToOther.TORIGHT:
		case relationToOther.TOLEFT:
			if (!other.GetComponent<StickyWalls>()) return;
			SticksToWalls stw = GetComponent<SticksToWalls>();
			if (!stw) return;
			if (stw.onWall && atWallTop(other)) landOnWallTop(other);
			break;
		}	
	}
Пример #3
0
	void stickToWallEdge(relationToOther relation, Collider other){
		float newHalfWidth = GetComponent<SticksToWalls>().onWallShape.x / 2;
		if (relation == relationToOther.TOLEFT) {
			changeX (other.bounds.center.x - (newHalfWidth + other.bounds.extents.x));
		} else if (relation == relationToOther.TORIGHT) {
			changeX(other.bounds.center.x + newHalfWidth + other.bounds.extents.x - sinkAmt);
		}
	}
Пример #4
0
	//	END WALL STICKING FUNCTIONS


	void moveToWallEdge(relationToOther relation, Collider other){
		if (relation == relationToOther.TOLEFT) {
			changeX (other.bounds.center.x - getTouchingDistanceX (other.gameObject));
		} else if (relation == relationToOther.TORIGHT) {
			changeX(other.bounds.center.x + getTouchingDistanceX(other.gameObject));
		}
	}
Пример #5
0
	void stickToEdge(relationToOther relation, Collider other){
		PhysicsObject po = GetComponent<PhysicsObject>();
		po.negateVertMovement();
		//po.enableSpeedChange = true;
		//po.changeSideSpeed(0);

		//	Close the sides if you should
		OpenSideObject oso = other.GetComponent<OpenSideObject>();
		if (oso && oso.openSides) oso.closeSides();
		//	Update the sticks to walls object
		SticksToWalls stw = GetComponent<SticksToWalls>();
		stw.onWall = true;
		wall = other;
		if (relation == relationToOther.TOLEFT) 
			stw.stickingToLeftSideOfObject = true;
		else stw.stickingToLeftSideOfObject = false;
		//	Move to the edge of the wall
		stickToWallEdge(relation, other);
		po.negateVertAcceleration();
	}
Пример #6
0
	//	Returns true if the velocity is correct for sticking to walls 
	//	i.e. the hero is jumping toward the wall
	bool checkCorrectVelocity(relationToOther relation, Collider other){
		PhysicsObject po = GetComponent<PhysicsObject>();
		if (relation == relationToOther.TOLEFT &&
		    po.vel.x < 0) return false;
		if (relation == relationToOther.TORIGHT &&
		    po.vel.x > 0) return false;
		return true;
	}
Пример #7
0
	//	Returns true if we have already crossed the plane of a block
	bool checkAlreadyInBlock(relationToOther relation, Collider other){
		if (collider.bounds.max.x > other.bounds.min.x + forgiveness &&
		    collider.bounds.min.x < other.bounds.min.x) return true;
		if (collider.bounds.min.x < other.bounds.max.x - forgiveness &&
		    collider.bounds.max.x > other.bounds.max.x) return true;
		if (collider.bounds.max.x < other.bounds.max.x &&
		    collider.bounds.min.x > other.bounds.min.x) return true;
		return false;
	}
Пример #8
0
	//	Manages the collisions for objects which stick to walls,
	//	If the object will react as if it does not stick to walls, returns false
	bool manageWallSticking(relationToOther relation, Collider other){
		PhysicsObject po = GetComponent<PhysicsObject>();
		SticksToWalls stw = GetComponent<SticksToWalls>();
		StickyWalls sw = other.GetComponent<StickyWalls>();
		if (!sw) return false;
		if (!sw.allows(relation)) return false;
		if (!stw) return false;
		if (po.onGround) return false;
		// Possible rotation solution -- however, needs to calculate touching distance differently
		//transform.rotation = Quaternion.Euler(0,0,90);
		if (checkAlreadyInBlock(relation, other)) return false;
		if (!checkCorrectVelocity(relation, other)) return false;
		//	If this is the case, we're in the air, we haven't already crossed the plane
		//	and we're headed in the direction of the wall. 
		print("sticking to edge");
		stickToEdge(relation, other);
		if (atWallTop(other)) landOnWallTop(other);
		return true;
	}
Пример #9
0
	void respondToSideHit(relationToOther relation, Collider other){
		//	Handle sticking to walls if we should, otherwise, don't
		if (gameObject.layer == candyLayer) return;
		if (manageWallSticking(relation, other)) return;
		//	If it has open sides, we go through them, so we don't adjust the position,
		//	unless we're sticking to the wall, in which case we do
		OpenSideObject hasOpenSide = other.GetComponent<OpenSideObject>();
		if (hasOpenSide && hasOpenSide.openSides) return;
		moveToWallEdge(relation, other);
	}