What the hell? Cannot convert float to int PROBLEM.

Why is this not working?

This is basically trying to get the heights of a certain point in the terrain, but that last part (“Get heights”) is causing a cannot convert to int issue.

Full error " error CS1503: Argument #1' cannot convert float’ expression to type `int’"

Its basically the positions bPosX1 and bPosY1… it simply wont work if I put them into the get heights. Without the getheights code everything works fine. So the convertion part of bpoX01 and bposY01 seems to be fine.

	        float bposX01 = bZone1.transform.position.x;
		float bposZ01 = bZone1.transform.position.z;
		float bposY01 = GameObject.Find("Terrain 0 3").GetComponent<Terrain>().SampleHeight(new Vector3(bposX01, 0, bposZ01));
		
		Vector3 nPos = (transform.position - terrainObject.gameObject.transform.position);
		Vector3 crd;

		crd.x = nPos.x / ter.terrainData.size.x;
		crd.y = nPos.y / ter.terrainData.size.y;
		crd.z = nPos.z / ter.terrainData.size.z;

		bposX01 = (int) (crd.x * terrain.terrainData.heightmapWidth); 
		bposY01 = (int) (crd.z * terrain.terrainData.heightmapHeight);
		//Offset...
		int ost = Inst1._size / 2;
		


//Get heights.

    	float[,] hPoints = ter.terrainData.GetHeights(bposX01-ost, bposY01-ost, size, size);		     

Please help… thanks.

float[,] hPoints = ter.terrainData.GetHeights(
(int)bposX01-ost, (int)bposY01-ost, size, size);

Replace line 30 with

 float[,] hPoints = ter.terrainData.GetHeights((float)bposX01-ost, (float)bposY01-ost, size, size);             

That should work. You are defining bposX01 and bposY01 as integers above, and calling them as floats later. You must do a conversion or else you’ll usually get that error.