x


"Attach" cloth.

Let's say I want to make a flag.

I make a stick, which is a cube with a long height. Then I make a cloth object. Technically, I want to somehow attach the cloth object to the cube object, simulating a flag... but I can't find a way to efficiently achieve such =/

more ▼

asked Nov 22, 2010 at 05:30 AM

avatar image

OmegaVemon
197 68 63 75

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

What you need to do is to add a collider to the object you want to attach the cloth to. Make sure the cloth mesh and the collider overlap in some vertices. Then, in the cloth component, expand the "Attached Colliders" field, and set the size to 1 (or how man colliders you want to attach). Expand "Element 0" and Drag the collider object to the "Collider" slot.

more ▼

answered Nov 22, 2010 at 11:00 AM

avatar image

jonas echterhoff ♦♦
10.8k 12 49 122

Thanks! Works perfectly!

Nov 22, 2010 at 06:08 PM OmegaVemon

oh so that's what u meant :o, good thing jonas knew then :) Wouldn't have known that.

Nov 22, 2010 at 06:39 PM Proclyon
(comments are locked)
10|3000 characters needed characters left

Hook up the object as a child to the parent ( Drop the "flag cloth" object onto the pole object. An action you can perform in the editor tab named "hierarchy" when your scene and project are loaded.

What happens now is that when you change the pole, the same will happen to the "flag cloth". You can specifically add effects or other to child which will not effect the parent (like wind blowing through it) if you want for the future.

more ▼

answered Nov 22, 2010 at 08:01 AM

avatar image

Proclyon
1.5k 31 28 51

The cloth might be the pole's child, but it still won't achieve an "attached" effect.

Nov 22, 2010 at 06:08 PM OmegaVemon
(comments are locked)
10|3000 characters needed characters left

In Unity 5 this changed. Here is what I ended up doing to create my flag.

  • create an empty game object to hold the parts

  • Add a child cylinder as the pole

  • Add a child cloth as the flag

  • Add a mesh renderer to the cloth

  • configure the renderer to have two materials, one normal, one with inverted normals

  • click 'Edit Constraints'

  • change to 'Paint' mode

  • select vertices on the mesh that you want constrained, for a flag, this is the full edge along the pole probably

  • configure some forces to make the flag flap

Images of the process above


Custom shaders I am using on the materials


 Shader "Custom/NoBackfaceCulling" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
     SubShader {
         Tags { "RenderType"="Opaque" }
         LOD 200
         Cull Off
         
         CGPROGRAM
         #pragma surface surf Lambert
 
         sampler2D _MainTex;
 
         struct Input {
             float2 uv_MainTex;
         };
 
         void surf (Input IN, inout SurfaceOutput o) {
             half4 c = tex2D (_MainTex, IN.uv_MainTex);
             o.Albedo = c.rgb;
             o.Alpha = c.a;
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }



 Shader "Custom/InvertedNormals" {
     Properties {
         _Color ("Main Color", Color) = (1,1,1,1)
         _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
         _BumpMap ("Normalmap", 2D) = "bump" {}
         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
     }
     SubShader {
         Tags {"IgnoreProjector"="True" "RenderType"="TransparentCutout"}
         LOD 300
         Cull Front
             
         CGPROGRAM
         #pragma surface surf Lambert alphatest:_Cutoff
 
         sampler2D _MainTex;
         sampler2D _BumpMap;
         float4 _Color;
 
         struct Input {
             float2 uv_MainTex;
             float2 uv_BumpMap;
         };
 
         void surf (Input IN, inout SurfaceOutput o) {
             half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
             o.Albedo = c.rgb;
             o.Alpha = c.a;
             o.Normal = -UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }



more ▼

answered Mar 17 at 08:29 AM

avatar image

sfusco
10 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

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:

x216
x212
x195
x117

asked: Nov 22, 2010 at 05:30 AM

Seen: 9241 times

Last Updated: Mar 17 at 03:34 AM