0 votes

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
in Engine by (113 points)

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

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.