here is some code I did some time ago on this subject.
` norm setup
sync on : sync rate 60
` position camera and trun off autocam
autocam off
position camera 0,0,0,-5
` cotlore backdrop
backdrop on
color backdrop rgb(0,0,0)
`start physic
phy start
`floor
make object cube 1,1
scale object 1,5000,10,5000
position object 1,0,-3,0
phy make rigid body static box 1
color object 1,rgb(0,0,0)
set object ambient 1,rgb(0,0,0)
set object specular 1,rgb(0,0,0)
set object specular power 1,3.0
`Metal coth
phy make cloth 22
phy set cloth dimensions 22, 10, 10, 0.2
phy set cloth position 22, -5, 10, -2
phy set cloth external acceleration 22, 0.0, 0.0, -8.0
phy build cloth 22
color object 22,rgb(255,0,0)
set object ambient 22,rgb(255,0,0)
set object specular 22,rgb(255,0,0)
set object specular power 22,3.0
`ball
make object sphere 24, 3
position object 24, 0, 0, 0
phy make rigid body dynamic sphere 24
color object 24,rgb(0,255,0)
set object ambient 24,rgb(0,255,0)
set object specular 24,rgb(0,255,0)
set object specular power 24,3.0
`box
make object box 26, 3, 2, 3
position object 26, 0, 0, 2
phy make rigid body dynamic box 26
color object 26,rgb(0,0,255)
set object ambient 26,rgb(0,0,255)
set object specular 26,rgb(0,0,255)
set object specular power 26,3.0
`hiden block
make object box 25, 10, 0.1, 10
phy make rigid body dynamic box 25
phy cloth attach rigid body 22, 25, 20.0, 0.7, 100.0
hide object 25
do
` out put info
set cursor 0,0 : print "Use mouse to look around, right & left mouse buttons to move camera"
set cursor 0,20 : print "Press space key to re-set objects positions"
set cursor 0,40 : print "press 1 for a cloth sphere, 2 for cloth cylinder, 3 for replace object with cloth"
set cursor 0,60 : print "press return to show wireframe"
set cursor 0,80 : print "cloth x: ";object position x(25)
set cursor 0,100 : print "cloth y: ";object position y(25)
set cursor 0,120 : print "cloth z: ";object position z(25)
`camera contrals
gosub camera
`re-set object positions & rotations
if spacekey()=1
`re-set position
phy set rigid body position 24,0,0,0
phy set rigid body position 25,0,20,0
phy set rigid body position 26,0,0,2
`re-set rotation
phy set rigid body rotation 24,0,0,0
phy set rigid body rotation 25,0,0,0
phy set rigid body rotation 26,0,0,0
endif
` delete old cloth and make a new one
if scancode()=2 then gosub change_cloth_1
if scancode()=3 then gosub change_cloth_2
if scancode()=4 then gosub change_cloth_3
` this will show the physic object wirefarame thats around the cloth object
if returnkey()=1
if object exist (25)=1 then show object 25
else
if object exist (25)=1 then hide object 25
endif
`update physics
phy update
`update sync end loop
sync
loop
phy end
end
`============================================================================================
` this is the cloth making thing, hope this helps if you don`t know how to make cloth objects
` this should help.
`this one makes a cloth sphere
change_cloth_1:
`make a temp object
if object exist(2) = 0
make object sphere 2,10
endif
`test to see if cloth exists
if phy get cloth exist(22) = 1 then phy delete cloth 22
`make an object out of cloth
if phy get cloth exist(22) = 0
phy make cloth from object 22,2
phy set cloth position 22, -5, 10, -2
phy set cloth external acceleration 22, 0.0, 0.0, -8.0
phy build cloth 22
color object 22,rgb(255,0,0)
set object ambient 22,rgb(255,0,0)
set object specular 22,rgb(255,0,0)
set object specular power 22,3.0
endif
`delete temp object
if object exist(2) = 1
delete object 2
endif
`test to see if hiden block exists
if object exist(25)=1 then delete object 25
`this tests to see if physic rigid body
if phy get rigid body exist (25) = 1 then phy delete rigid body 25
`make new hiden block
if object exist(25)=0
make object sphere 25,10 :`,10,10
set object wireframe 25,1
phy make rigid body dynamic box 25
phy cloth attach rigid body 22, 25, 20.0, 0.7, 100.0 :` this is the link between the cloth and object.
phy set rigid body position 25,0,20,0
phy set rigid body rotation 25,0,0,0
hide object 25
endif
return
` this one make a cloth cube
change_cloth_2:
`make a temp object
if object exist(2) = 0
make object cylinder 2,10
endif
`test to see if cloth exists
if phy get cloth exist(22) = 1 then phy delete cloth 22
`make an object out of cloth
if phy get cloth exist(22) = 0
phy make cloth from object 22,2
phy set cloth position 22, -5, 10, -2
phy set cloth external acceleration 22, 0.0, 0.0, -8.0
phy build cloth 22
color object 22,rgb(255,0,0)
set object ambient 22,rgb(255,0,0)
set object specular 22,rgb(255,0,0)
set object specular power 22,3.0
endif
`delete temp object
if object exist(2) = 1
delete object 2
endif
`test to see if hiden block exists
if object exist(25)=1 then delete object 25
`this tests to see if physic rigid body
if phy get rigid body exist (25) = 1 then phy delete rigid body 25
`make new hiden block
if object exist(25)=0
make object box 25,10,10,10
set object wireframe 25,1
phy make rigid body dynamic box 25
phy cloth attach rigid body 22, 25, 20.0, 0.7, 100.0 :` this is the link between the cloth and object.
phy set rigid body position 25,0,20,0
phy set rigid body rotation 25,0,0,0
hide object 25
endif
return
`this one remakes the old cloth sheet
change_cloth_3:
`test to see if cloth exists
if phy get cloth exist(22) = 1 then phy delete cloth 22
`make an object out of cloth
if phy get cloth exist(22) = 0
phy make cloth 22
phy set cloth dimensions 22, 10, 10, 0.2
phy set cloth position 22, -5, 10, -2
phy set cloth external acceleration 22, 0.0, 0.0, -8.0
phy build cloth 22
color object 22,rgb(255,0,0)
set object ambient 22,rgb(255,0,0)
set object specular 22,rgb(255,0,0)
set object specular power 22,3.0
endif
`test to see if hiden block exists
if object exist(25)=1 then delete object 25
`this tests to see if physic rigid body
if phy get rigid body exist (25) = 1 then phy delete rigid body 25
`make new hiden block
if object exist(25)=0
make object box 25,10, 0.1, 10
set object wireframe 25,1
phy make rigid body dynamic box 25
phy cloth attach rigid body 22, 25, 20.0, 0.7, 100.0 :` this is the link between the cloth and object.
phy set rigid body position 25,0,20,0
phy set rigid body rotation 25,0,0,0
hide object 25
endif
return
`==========================================================================================
` camera gosub
camera:
OldCamAngleY# = CameraAngleY#
OldCamAngleX# = CameraAngleX#
CameraAngleY# = wrapvalue ( CameraAngleY# + mousemovex ( ) * 0.4 )
CameraAngleX# = wrapvalue ( CameraAngleX# + mousemovey ( ) * 0.4 )
rotate camera 0,curveangle ( CameraAnglex#, OldCamAnglex#, 24 ),curveangle ( CameraAngleY#, OldCamAngleY#, 24 ),0
if mouseclick() = 1 then move camera 0,1
if mouseclick() = 2 then move camera 0,-1
return
soul sucking devils, twisted body of the damed, slivering slim drips from every poor, sin licking at your ears, and the smell stinging your eyes, and if you don't like it, get out of my kitchen!