How to get the edge of a 3D object?

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

How can I get the edge of a 3d object (mesh or collision)?, like the one in the picture attached?

The idea is to make the player hang and slide along the edge (like in Metal Gear), of any arbitrary 3d object, so I thought about using the edge, and restrict the player’s movement based on that vector.

I’ve been looking the MeshDataTool, but I’m not sure if this tool can be used for this purpose and how to do it.

Thank you!

:bust_in_silhouette: Reply From: VTVL

I’m new to the forums but I’ll try to help:

You could use the AABB class to find to the coordinates of the top plane of the object (as shown below in the get_upwards_plane function).

This is where I think it gets tricky, trying to figure out when you should let the object in question fall or stick to the edge of the wall. One way you could do it is by having a collision box and detecting collision, and figuring out the point of collision, for example using CharacterBody3D’s get_slide_position(), and getting the .position attribute from that.

Sample Code (not tested):

func get_upwards_plane():
   mesh = get_node(mesh_path).get_aabb() # get the bounding box of the mesh
   corner_1_pos = mesh.position # these are Vector3s
   corner_2_pos = mesh.end
   corner_1_pos.y = corner_2_pos.y # getting the top 2d plane

func is_collision_in_plane():
   collision_pos = self.get_slide_collision().position
   if is_inside_of_plane(): # this would be several if statements if the position is inside/on top of the coords of the two corner_pos
      velocity.y == 0 # sample of cancelling velocity on the y to sit on the edge

this looks like it could be!

thank you very much, ill study the AABB class and will try to figure it out!

hermo | 2023-04-03 09:25