How to pose vertices.

 0 Well I want my mesh - plane should swim over water surface as paper. For that i would like modify position of mesh vertices, but my script doesn't work ( ``````function Start(){ thisMatrix = transform.localToWorldMatrix; mesh= GetComponent(MeshFilter).mesh; vertices = mesh.vertices; } function Update(){ for (var i = 0; i < vertices.Length; i++){ Mypos = thisMatrix.MultiplyPoint3x4(vertices[i]); Mypos.y+=20; if (Physics.Raycast (Mypos, -Vector3.up,hit, 30)) { print(hit.point); vertices[i] = hit.point; } mesh.vertices = vertices; mesh.RecalculateBounds(); } } `````` more ▼ asked Feb 11 '12 at 05:42 PM 2dkot 76 ● 15 ● 21 ● 28 Any suggestion? Feb 12 '12 at 12:16 PM 2dkot as far I understand I should convert world coordinates to mesh vertices coordinates or something... Feb 12 '12 at 12:36 PM 2dkot add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

1 answer: sort voted first
 0 Found solution:I needed transform.worldToLocalMatrix to transform world coordinates to local mesh coordinates. this whole script: ``````var mesh : Mesh; var vertices : Vector3[]; var Mypos:Vector3; var Mypos1:Vector3; var hit : RaycastHit; var thisMatrix: Matrix4x4; var meshMatrix:Matrix4x4; function Start(){ thisMatrix = transform.localToWorldMatrix; meshMatrix = transform.worldToLocalMatrix; mesh= GetComponent(MeshFilter).mesh; vertices = mesh.vertices; } function Update(){ for (var i = 0; i < vertices.Length; i++){ Mypos = thisMatrix.MultiplyPoint3x4(vertices[i]); Mypos.y+=100; if (Physics.Raycast (Mypos, -Vector3.up,hit, 120)) { Mypos = meshMatrix.MultiplyPoint3x4(hit.point;); vertices[i] = Mypos; } } mesh.vertices = vertices; mesh.RecalculateBounds(); } `````` more ▼ answered Feb 12 '12 at 12:49 PM 2dkot 76 ● 15 ● 21 ● 28 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
Your answer

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x139

asked: Feb 11 '12 at 05:42 PM

Seen: 428 times

Last Updated: Feb 12 '12 at 12:49 PM