raycast to determine height of terrain

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By tproper

Hey, I am trying to get the height of my terrain at a given X,Z point. Below is my code. I know the terrain has the correct collisionshape since I am able to walk on it correctly, but when I raycast down onto it to get the Y height I’m getting incorrect numbers (usually all below 1) which causes the below code to put trees inside the hills on my terrain. Am I using the raycast incorrectly?

if(can_generate_tree):
		self.translation = Vector3(x, 1000, z)
		if($TreeCaster.is_enabled() && $TreeCaster.is_colliding()):
				var colliding_object = $TreeCaster.get_collider()
				if(colliding_object.get_name() == "TerrianStaticBody"):
					if($TreeCaster.get_collision_point().y > max_y_of_treeline):
						can_generate_tree = false
					else:
						y_pos = $TreeCaster.get_collision_point().y
				else:
					can_generate_tree = false
		else:
			can_generate_tree = false

Where I get the Y pos is:

y_pos = $TreeCaster.get_collision_point().y

Maybe it would help if you uploaded the project so that we can see where the problem is originating.

SIsilicon | 2018-09-27 02:32