0 votes

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!

screenshot

Godot version 4.0.1
in Engine by (78 points)

1 Answer

0 votes
Best answer

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 getupwardsplane 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
by (50 points)
selected by

this looks like it could be!

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

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.