- Home /
Why is the mesh position changing instead of its scale?
Am trying to change the scale of a specific part of the mesh based on the vertex color. Now it works because only the blue vertices are affected, but for some reason they change their position instead of their scale:
Color [] color;
Vector3[] vertices;
Vector3 vertex;
void Start ()
{
vertices = GetComponent <MeshFilter> ().mesh.vertices;
color = GetComponent<MeshFilter> ().sharedMesh.colors;
}
void Update ()
{
for (int i = 0; i < vertices.Length; i++)
{
if (Input.GetKey (KeyCode.T))
{
if (color [i] == Color.blue)
{
vertex = vertices [i];
vertex.x += 1.0f;
vertex.z += 1.0f;
vertices [i]= vertex;
}
}
}
this.GetComponent<MeshFilter> ().mesh.vertices = vertices;
}
Answer by JVene · Aug 15, 2018 at 07:05 PM
This code:
vertex.x += 1.0f;
vertex.z += 1.0f;
is moving the vertex x and z positions. Scaling would be performed by multiplication (by a number between 1 and 0 to shrink, over 1 to expand), but addition would merely move points.
That said, merely switching to a multiplication by some factor may not produce the results you require, because the origin of the mesh would be the center of the expansion/contraction. You may need to consider some particular central point upon which the expansion/contraction is performed.
Your answer
Follow this Question
Related Questions
How do I offset the scaling center for a cube 1 Answer
Memory Usage on resize 1 Answer
Scaling an instantiated object based on prefab, but not prefab 2 Answers
GUI scaling on mobile 1 Answer
Scaling related to damage 2 Answers