Answer the question
In order to leave comments, you need to log in
How to determine the transform.position of the extreme vertices of a 2d object?
Hello.
I am making a simple level generator for a 2D platformer, where the beginning of another is joined at the end of one platform, i.e. to place the platform, I use two points, its beginning and end, respectively.
The platform is made in such a way that the pivot point is its beginning, that is, the transform.position of the object is its beginning, which will be equal to the end point of the previous platform, in such a simple way the level will be generated, and the question is: how can I determine the end point of the platform? The pivot point is used as the starting point, calculating manually (adding the platform length to the starting point) is not an option, because the size of the platform and sprites can still be changed and adjusted, and creating one more object in the form of a child point that will be the end of the platform is too cumbersome, you will need to then each time to look for it, you need to automate this process so that when the object is resized, the code automatically searches for the extreme points of the platform in order to attach others to them.
MB in the same way will more correctly determine the starting point.
Somewhere for a long time I saw that somehow they turned to the boxcollider2d component and took its extreme vertex, but I don’t remember exactly how it was, in the documentation the unit did not find approximately similar functions I needed (for example, there is a center function that defines the center itself, but I you need to define for example the leftmost, or the top right point, as it is for example in the sprite editor when it automatically determines where to place the pivot).
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question