- Home /
How to place a transform on the center of one face of a cube
Is there a way to do so efficiently?
But what do you have a problem with? You can't calculate the center of a face? You can't move an object? You have an implementation that you think could be better?
Answer by bpaynom · Jul 23, 2019 at 09:20 AM
someTransform.position = yourCubeTransform.position + yourCubeTransform.forward.normalized * yourCubeSize * 0.5f;
You can use forward, up, right, -forward, -up or -right, depending on where you want to put your object.
Thank you! I modified it a little bit: transformToPlace.position = yourCubeTransform.position + (yourCubeTransform.forward.normalized * yourCubeTransform.localScale.z)/2;
Yeah, that works for primitive cube of 1x1x1. It doesnt for other custom made cubes. :)
Your answer
Follow this Question
Related Questions
Perpendicular forward :-) 0 Answers
Transforming a GameObject with an unattached script 1 Answer
Transform rotation 2 Answers
Line renderer transform position problem 1 Answer
transform.position 3 Answers