Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_aabb() returns AABBs with incorrect position-values #42095

Closed
okapii opened this issue Sep 15, 2020 · 5 comments
Closed

get_aabb() returns AABBs with incorrect position-values #42095

okapii opened this issue Sep 15, 2020 · 5 comments

Comments

@okapii
Copy link

okapii commented Sep 15, 2020

Godot version:
Godot v3.2.3.rc6.official

OS/device including version:
MacBook Pro (13", 2020)
2,3 GHz Quad-Core Intel Core i7
16 GB 3733 MHz LPDDR4X
Intel Iris Plus Graphics 1536 MB

Issue description:
I hope that this is not a conceptual misunderstanding on my end but it seems to me that the position property of AABBs is reporting incorrect values.

screenshot_aabb

extends Spatial

func _ready():
	print($box1.get_aabb())
	print($box2.get_aabb())
	print($box2.get_aabb())

Running this code on the scene shown above yields the following output:

  • -0.5, -0.5, -0.5 - 1, 1, 1
  • -0.5, -0.5, -0.5 - 1, 1, 1
  • -0.5, -0.5, -0.5 - 1, 1, 1

As one can see all position values are identical despite the cubes being positioned differently.

Originally I assumed that this was by design and that one would have to offset the AABBs utilising the object's origin-coordinate to get the correct position of the AABB in the global world. But that surely can't be right as this would result in varying / wrong values depending on where the origin is positioned in relation to the actual geometry.

Steps to reproduce:
See above

Minimal reproduction project:
200915_Godot_AABB.zip

@okapii okapii closed this as completed Sep 15, 2020
@Calinou
Copy link
Member

Calinou commented Sep 15, 2020

@okapii Did you find a solution to this issue?

@okapii
Copy link
Author

okapii commented Sep 15, 2020

@Calinou : I thought I did. But by now I am even more stumped. :) Right now I am just unsure if this is a bug or an issue on my end which is why I did not reopen things.

I have come to realise that the AABBs never reflect position, rotation and scale of instances. get_aabb() always leads to the bounding box of the unrotated, unscaled object positioned at the origin resulting in false collision detection. Position can be accounted for by altering the AABBs position-property according to the instance's origin but I am fairly stumped now as to how to account for rotation and scale. Sadly I can't find too much information on the whole AABB topic in Godot in general.

@okapii okapii reopened this Sep 15, 2020
@okapii
Copy link
Author

okapii commented Sep 15, 2020

As I still can't seem to find a solution here is an illustration of the issue. It is still the basic code form above.

Scene in perspective
200915_aabb

Intersection false
200915_aabb_false

Intersection true
200915_aabb_true

extends Spatial

func _ready():
	var b1 = $box1.get_aabb()
	var b2 = $box2.get_aabb()

	b1.position += $box1.translation
	b2.position += $box2.translation

	print(b1.intersects(b2))

As one can see what matters is not the actual position / rotation / scale (as seen on the left side of the images) but the default rotation where in the 2nd one this leads to a small intersection while in reality both versions should report "true" as the bounding boxes should intersect.

@pouleyKetchoupp
Copy link
Contributor

Could you check if get_transformed_aabb gives you the right result? It looks like get_aabb is the bounding box in local space, while get_transformed_aabb is in world space.

@okapii
Copy link
Author

okapii commented Sep 16, 2020

Yeh, that was the obvious solution I was afraid of potentially just not seeing. So yeah, thanks, that worked!

I guess the method is not documented in https://docs.godotengine.org/de/stable/classes/class_aabb.html for being inherited from VisualInstance?

@okapii okapii closed this as completed Sep 16, 2020
Calinou added a commit to Calinou/godot that referenced this issue Sep 16, 2020
This also clarifies that `get_aabb()` returns the AABB in local space.

See godotengine#42095.
akien-mga pushed a commit that referenced this issue Sep 16, 2020
This also clarifies that `get_aabb()` returns the AABB in local space.

See #42095.

(cherry picked from commit 9712f8f)
MarcusElg pushed a commit to MarcusElg/godot that referenced this issue Oct 19, 2020
This also clarifies that `get_aabb()` returns the AABB in local space.

See godotengine#42095.
huhund pushed a commit to huhund/godot that referenced this issue Nov 10, 2020
This also clarifies that `get_aabb()` returns the AABB in local space.

See godotengine#42095.

(cherry picked from commit 9712f8f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants