I wanted to slide a player along a rectangle by using transform.translate until it reaches the edge of said rectangle.
The problem is transform.position gives me a vector3 at the center of the transform not one side of it.
Does anyone know how I can get the positional value for the edge of one side of a rectangular transform?
I’ve made an asset to solve this problem
Move unity 2D objects with a single line of code
without worrying about scale ,sprite pivot , collider size or offset.
Example:
place the player at the start of the level using a single line of code:
player.MoveBottomLeft ( ground.GetTopLeft () )
Supports:
-
Sprite Renderer
-
Box Collider 2D
-
Circle Collider 2D
Asset Store URL: Object Edges 2D | 3D Characters | Unity Asset Store
Documentation: Object Edges 2D - Cyborg assets
Video Tutorial: Easily Move Unity Objects ( Object Edges 2D tutorial ) - YouTube
Hope it helps you & saves your time
if i understood right, you are using sprites and BoxCollider2D. Then you can get this information from collider center and size, say one edge would have an x value of, center.x + (size.x / 2).