The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

This is more of an answer to a question I've been having that I thought I would share because I've been struggling on it for a couple of days and don't want others to face the same issue.

I am attempting to get the center of a Mesh Instance for level loading purposes, but even using the Mesh Data Tool and averaging the vertices doesn't seem to work.

The solution I found was to use MeshInstance.Mesh.get_aabb() which returns an aabb:

I then used this aabb to calculate the center using this formula:

var aabb: AABB = mesh.get_aabb()
var center = aabb.position + aabb.size / 2

That code returns the center of the aabb of the mesh.

The quest to find this solution was a bit of a struggle because of how the get_aabb() differentiates itself from the custom aabb found in the inspector on the Mesh Instance. Maybe some documentation better explaining the difference could help?

Anyway, hope this helps whoever had the same problem!

Godot version 3.4
in Engine by (32 points)

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.