Beispiel #1
0
 public RLPt(RacingLine line, Vector3 pos)
 {
     Line = line;
     Pos  = pos;
 }
Beispiel #2
0
	private bool findAltRacingLine(bool aShorterOnly) {
		List<RacingLine> allRacingLines = RaceTrack.REF.racingLines;
		for(int i = 0;i<allRacingLines.Count;i++) {
			bool a = (i>0&&allRacingLines[i-1]==this.myRacingLine);
			bool b = (i<allRacingLines.Count-1&&allRacingLines[i+1]==this.myRacingLine);
			if(a||b) {
				RaceLinePoint r = allRacingLines[i].pointAtIndex(currentPoint.thisIndex);
				float currentDistanceToFinish = this.currentPoint.distanceToFinish+(Vector3.Distance(this.transform.position,this.currentPoint.transform.position));
				float altLineDistanceToFinish =	r.distanceToFinish+(Vector3.Distance(this.transform.position,r.transform.position));
				bool shorter = altLineDistanceToFinish<currentDistanceToFinish;
				
				if(!aShorterOnly||altLineDistanceToFinish<currentDistanceToFinish) {
					// We want to move to a different race line if we can
					
					RaceLinePoint p = allRacingLines[i].pointAtIndex(currentPoint.thisIndex-1);
					Vector3 there = p.transform.position;
					
					Vector3 diff = p.transform.position-this.transform.position;
					float dist = Vector3.Distance(allRacingLines[i].pointAtIndex(currentPoint.thisIndex-1).transform.position,this.transform.position);
					
					
					// Spherecast towards the current point on this line, if there is something there, lets
					RaycastHit hit;
					
					float distanceToObstacle = 0;
					
					// Cast a sphere wrapping character controller 10 meters forward
					// to see if it is about to hit anything.
					Vector3 here = this.transform.position;
					here.y += 1f;
					there.y += 1f;
					Vector3 left = (this.transform.right*-1)*(Vector3.Distance(here,there))+this.transform.position;
					Vector3 right = (this.transform.right)*(Vector3.Distance(here,there))+this.transform.position;
					left.y+=1f;
					right.y+=1f;
					// I don't know whether this is on left or right of us right now, lets see whats closest to "There"
					Vector3 sideways = right;
					if(Vector3.Distance(left,there)<Vector3.Distance(right,there)) {
						sideways = left;
					}
					Vector3 infrontAndLeftDiff = there-sideways;
					Vector3 behind = sideways-infrontAndLeftDiff;
					Vector3 behindDouble = sideways-infrontAndLeftDiff*3;
					Vector3 infrontAndSide = sideways+infrontAndLeftDiff/2;


					if((this.horseInTargetLaneAtVector(here,there,allRacingLines[i])!=null)||
					   (this.horseInTargetLaneAtVector(here,sideways,allRacingLines[i])!=null)||
					   (this.horseInTargetLaneAtVector(here,behind,allRacingLines[i])!=null)||
					   (this.horseInTargetLaneAtVector(here,infrontAndSide,allRacingLines[i])!=null)||
					   (this.horseInTargetLaneAtVector(here,behindDouble,allRacingLines[i])!=null)) {
	
					} else {
						this.myRacingLine = allRacingLines[i];
						if(currentPoint.thisIndex>0)
							prevPoint = allRacingLines[i].pointAtIndex(currentPoint.thisIndex-1);
 
						this.currentPoint = allRacingLines[i].pointAtIndex(currentPoint.thisIndex);
						useMidway = true;
						return true;
					}
					
					
				}
			}
		}
		// No suitable race line found
		return false;
	}
Beispiel #3
0
	public void initFromPackage(SFSObject aObject) {
		float[] pos = aObject.GetFloatArray("pos");
		Vector3 currentPosition = this.transform.position;
		Vector3 position = new Vector3(pos[0],pos[1],pos[2]);
		originalPosition = this.transform.position;
		float[] spds = aObject.GetFloatArray("spds");
		byte input = aObject.GetByte("in");
		this.speed = spds[0]; 
		this.desiredSpeed = spds[1];
		this.currentPoint = GameObject.Find(aObject.GetUtfString("rp")).GetComponent<RaceLinePoint>();
		this.myRacingLine = GameObject.Find(aObject.GetUtfString("r")).GetComponent<RacingLine>();
		this.transform.position = position;	


	}
Beispiel #4
0
	private HorseController horseInTargetLaneAtVector(Vector3 aHere,Vector3 aThere,RacingLine aLine) {
		RaycastHit hit;
		Debug.DrawLine(aHere,aThere); 
		if(Physics.Linecast(aHere,aThere,out hit)) {
			if(hit.collider.gameObject.tag=="Player") {
				HorseController h = hit.collider.GetComponent<HorseController>();
				if(h.myRacingLine==aLine) {
					return h;
				}
			}
		}
		return null;
	}
Beispiel #5
0
	void findStartRaceLine() {
		GameObject[] g = GameObject.FindGameObjectsWithTag("RacingLine");

		RacingLine closest = g[0].GetComponent<RacingLine>();
		float closestDist = float.MaxValue;
		for(int i = 0;i<g.Length;i++) {
			RacingLine r = g[i].GetComponent<RacingLine>();
			float dist = r.getDistanceFromHorse(this.transform.position);
			if(dist<closestDist) {
				closestDist = dist;
				closest = r;
			}
		}
		myRacingLine = closest;
		

	}