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

Make use of NavigationObstacle2D's transform #99030

Merged
merged 1 commit into from
Nov 12, 2024

Conversation

tracefree
Copy link
Contributor

@tracefree tracefree commented Nov 10, 2024

Fixes #95820

2D version of #96730. Partially an enhancement and partially a fix because previously, editing a NavigationObstacle2D was broken if it or any of its ancestor nodes had a rotation, scale, or skew applied.

The only thing missing as far as I can tell is to modify NavigationObstacle2DEditor so that the vertices are transformed by the modified safe transform (which prevents non-uniform scaling), as discussed on RocketChat.

Edit: This should now be fully consistent and have feature parity with the 3D version of this PR. But I have not tested it extensively and the code may not be completely in line with Godot's conventions and guidelines, would need someone more familiar with the codebase to review and give feedback on it please 🙂

@smix8 smix8 added this to the 4.x milestone Nov 10, 2024
@tracefree tracefree force-pushed the obstacle_2d_transform branch from 262a865 to 6a70062 Compare November 10, 2024 19:42
@tracefree tracefree marked this pull request as ready for review November 10, 2024 19:48
@tracefree tracefree requested review from a team as code owners November 10, 2024 19:48
@tracefree tracefree force-pushed the obstacle_2d_transform branch from 6a70062 to c373563 Compare November 10, 2024 19:54
@tracefree tracefree force-pushed the obstacle_2d_transform branch from c373563 to 8928517 Compare November 10, 2024 22:17
@tracefree
Copy link
Contributor Author

tracefree commented Nov 10, 2024

Reverted changes meant to prevent obstacle vertices to be affected by zero or negative scaling like in the 3D version and only show a warning in that case instead. The reason is that doing so would require modification to sensitive code in AbstractPolygon2DEditor which is already planned to be moved away from as a dependency for NavigationObstacle2D, it makes more sense to reinstate that behavior once that refactor has been finished.

@smix8
Copy link
Contributor

smix8 commented Nov 11, 2024

When I change the NavigationObstacle rotation the radius debug changes size.

In the setup I have both the parent Node2D and the child NavigationObstacle scaled and rotated and translated.

@tracefree
Copy link
Contributor Author

tracefree commented Nov 11, 2024

I think this may be a side effect of the logic used to ensure the radius is scaled only uniformly by the value of the largest global scale axis, but you are right that it feels strange and I'll take a look to see if that really is the case or if there is a coding mistake.

@smix8
Copy link
Contributor

smix8 commented Nov 11, 2024

I guess it is just the usual flaw with the Transform2D that has no real scale compare to 3D but just a rotation depending fake scale.

@tracefree
Copy link
Contributor Author

tracefree commented Nov 11, 2024

Yeah, it looks like that's what's happening here. For the scale factor of the radius, I take the largest value of the global_scale of the obstacle node, clamped to 0.0001 to prevent it from becoming zero or negative.

How would you like me to handle this? I don't really see another sensible way of using the transform's scale to influence the radius, but the fact that it depends on the rotation is very counter-intuitive and I imagine would lead several people to report it as a bug. Do we leave it as is, or should we maybe just leave the radius alone and let it ignore the node transform? And if the latter, should I change the 3D PR to do it like that as well for consistency?

If we stay with the current behavior I could change the warning that is already displayed when scaling a radius-based obstacle non-uniformly to also warn about unexpected behavior. Currently it just says "The agent radius can only be scaled uniformly. The largest scale value along the two axes will be used and skew is ignored."

@smix8
Copy link
Contributor

smix8 commented Nov 11, 2024

I would say just leave it as is, or add extra to the warning so people know that when they scale things the screw up same as they do with physics.

@tracefree tracefree force-pushed the obstacle_2d_transform branch from 8928517 to e39fc3e Compare November 11, 2024 22:35
@tracefree
Copy link
Contributor Author

Alright! I expanded the warning, added an additional warning for skew, and added a clarifying comment somewhere else in the code.

Copy link
Contributor

@smix8 smix8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the transform change.

Still needs code review.

@smix8 smix8 modified the milestones: 4.x, 4.4 Nov 12, 2024
Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style seems fine to me.

@tracefree
Copy link
Contributor Author

tracefree commented Nov 12, 2024

Thank you for reviewing! I realized there is still one more missing functionality (transforming the vertices for the avoidance system) as discussed on RocketChat, so please don't merge the PR just yet 🙂

@Repiteo Repiteo merged commit e960aa3 into godotengine:master Nov 12, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Nov 12, 2024

I realized there is still one more missing functionality (transforming the vertices for the avoidance system) as discussed on RocketChat, so please don't merge the PR just yet 🙂

NOOOOOO, I SAW THIS TOO LAAAATE 😭

It's all good tho, just handle that in a separate PR & I'll fast-track a merge for it 👍

@tracefree
Copy link
Contributor Author

Haha no problem! I should have converted the PR to a draft, my bad. I'll need to fix both this and the 3D version of this PR anyway because of rebasing issues from another PR that was just merged so a making separate PR is suitable for that anyway.

@tracefree tracefree deleted the obstacle_2d_transform branch November 15, 2024 13:40
@tracefree
Copy link
Contributor Author

This is the follow up PR that implements what I missed in this one: #99176 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NavigationObstacle2D does not rotate vertices when node is rotated
4 participants