- Home /
Position of a cloth?
Hello,
I am trying to make the camera follow a cloth.
I added a empty game object and then upon it, I added the interactive cloth and cloth renderer.
Then I added a mesh through the interactive cloth inspecter pane.
Now I added a script on the camera to follow the cloth when it moves by transformation of the game object.
The cloth by the way, moves upon gravity and falls free.
Now when I look closing, the game object stays where it is supposed to be and the cloth does nt have any object with it.
Kindly let me know if I am wrong at any place and if not, what is the best alternative way to implement it.
Thank you,
regards, Karsnen.
so.. 1. is the camera not following the cloth when free falling? or 2. do you not want the cloth to free fall?
Yes I want the camera to follow the cloth, which it is not following. and (2) currently the cloth is FALLING FREE (no problem with this).
Answer by J Lam · Jul 16, 2012 at 01:12 PM
Cloth simulation happens to deform the vertices instead of "move" the object, therefore the gameObject would be still from the Transform point of view, and child-parent relationship is not able to help in this case.
The way to move the camera along with the cloth is to track the vertex, Unity provide a function to retrieve the vertex position. You can refer to
Mesh.vertices
only one vertex is enough, you could simply track the first vertex in the mesh or any ID you want in a FixUpdate or Update and adjust the camera transform according to that vertex position.
Answer by programmrzinc · Jun 21, 2012 at 02:51 PM
attach the cloth to the empty game object first if you haven't done so.
I think I did that. Anyway, I am going to try it again.
Well. Now what I did was,
Created an empty gameobject to (0,0,0).
Added a cloth renderer which also added interactive cloth.
I clicked on "$$anonymous$$esh" on the inspector and then added the mesh.
WHen I play, It had to fall upon gravity which in fact it did. But the empty gameobject just stayed at (0,0,0).
ok. this is what is happening. The camera is on the gameobject, which is NOT free falling. for the camera to work, we either need to set the camera to follow the "cloth" or have the gameobject attached to the cloth. we need to try to fix this in some way
"Camera on the gameobject" - Do you mean by child-parenting.
Follow the cloth - I think I have not tried it. I also think, it would work. If so, how? Something lIke this?
//On the Camera
public InteractiveCloth cloth; then get it's position???
As for as child-parenting is concerned. I think I tried that too. It did not work as the gameobject just stay at it's initial position.
$$anonymous$$oreover... I just did things like I pointed out. But still, I am not sure where I am going wrong.
It has to be either I am doing a stupid simple mistake or I am missing something.