private Tuple <CCollidable, float> GetObjectCollision(Vector3 point) { float Height = 0.0f; List <Tuple <CCollidable, float> > heights = new List <Tuple <CCollidable, float> >(); for (int i = 0; i < CObjectManager.MAX_INSTANCES; i++) { if ((CObjectManager.Instance.pGameObjectList[i] != null) && Object.ReferenceEquals(typeof(CCollidable), CObjectManager.Instance.pGameObjectList[i].GetType())) { //getting the reference CCollidable otherInstance = (CCollidable)CObjectManager.Instance.pGameObjectList[i]; heights.Add(new Tuple <CCollidable, float>(otherInstance, otherInstance.GetHeightAt(point.X, point.Y, point.Z))); } } int ind = 0; if (heights.Count > 0) { //remove the ones above the player float min = z; //foreach (float f in possibleHeights) for (int i = 0; i < heights.Count; i++) { float f = heights[i].Item2; float diff = z - f; //Console.WriteLine(f + " " + z + " " + diff); if (diff >= -2.0f && diff < min) // { Height = f; min = diff; ind = i; } } //Height = min; } if (Height > 0) { return(heights[ind]); } else { return(new Tuple <CCollidable, float>(null, 0.0f)); } }
private Vector3 WallCollisionAt(Vector3 point, float rad, float height) { Vector3 objectCollision = new Vector3(0, 0, 0); for (int i = 0; i < CObjectManager.MAX_INSTANCES; i++) { if ((CObjectManager.Instance.pGameObjectList[i] != null) && Object.ReferenceEquals(typeof(CCollidable), CObjectManager.Instance.pGameObjectList[i].GetType())) { //getting the reference CCollidable otherInstance = (CCollidable)CObjectManager.Instance.pGameObjectList[i]; Vector3 col = otherInstance.PointInWall(point, rad, height); if (!col.Equals(new Vector3(0, 0, 0))) { objectCollision = col; } } } return(objectCollision.Equals(new Vector3(0, 0, 0)) ? CLevel.Instance.PointInWall(point, rad, height) : objectCollision); }