- Home /
Resize Plane?
is is possible to resize the plane to the distance of two sphere. I hope you can understand me. The left downer corner to the left sphere the right upper to the right spehere.Like a selection box. I want to cover with the plane an entire region with two Vector3
Answer by zharik86 · Jun 01, 2014 at 07:11 PM
Yes, of course, probably. It is the simple geometrical task. But at first the "correct" plane is necessary to us. (scale on guides equal 1 will give the size 1x1 in a world). It is possible to create the plane in 3dmax and to import. If isn't present, instead of the plane it is necessary to take a standard cube and, for example, scale on a y axis to make equal 0.1 or less. So, we have all necessary, now a small code(write on CSharp):
public Transform sphere1 = null; //our sphere number 1
publuc Transform sphere2 = null; //our sphere number 2
void Start() {
//if you scale your plane in xz, then
Vector3 pos1 = sphere1.position;
Vector3 pos2 = sphere2.position;
pos1.y = this.transform.position.y;
pos2.y = this.transform.position.y;
//Sets new position of our plane
this.transform.position = 0.5f * (pos1 + pos2);
//Calculate new scale for plane
float scaleX = Mathf.Abs(pos1.x - pos2.x);
float scaleY = this.transform.localScale.y;
float scaleZ = Mathf.Abs(pos1.z - pos2.z);
this.transform.localScale = new Vector3(scaleX, scaleY, scaleZ);
}
And attach this script to your plane.
Your answer
Follow this Question
Related Questions
How to align the bottom of a GameObject with the ground? 1 Answer
why the real size of a object doesn't show in the inspector? 0 Answers
Scale mesh between two Vectors 1 Answer
Projecting a point on plane 1 Answer
How to Rotate Plane of Cube Around its Center? (Rotate Vectors Around Point/Axis/Direction) 1 Answer