- Home /
How would i find the center of an object with a Y axis offset to find the center on the top face?
Im trying to make a climbing system (Player climbs ontop of a cube). Im using collider.bounds.center to get the center of the object but what would i have to do to get the center on the top face of the object?
Thankyou for any help !
Answer by MHernandezOlmo · Jul 23, 2020 at 09:26 AM
Hi @Damiano96, you are looking for bounds.extents. that would give you half of the size of the bounds.
Your center point is collider.bounds.center.
Your collider size on y axis (half of it, since you already have the center) is bound.extents.y.
So the center of the top face would be:
Vector3 colliderCenter = Collider.Bounds.center;
topFaceCenter = new Vector3 (colliderCenter.x, colliderCenter.y + Collider.bounds.extents.y, colliderCenter.z)
Thankyou very much! I got it working using the transform of the object but I prefer using your method with Collider.Bounds!
Your answer
Follow this Question
Related Questions
How Does OnTriggerEnter() Work? 0 Answers
Bounds.Contains not working properly 3 Answers
Make Collider equal to renderer bounds? 2 Answers
Multiple Cars not working 1 Answer
How to set parent collider equal to child collider visually? 2 Answers