Jump to content

joints trouble


AggrorJorn
 Share

Recommended Posts

I am trying to create a rope. I have been experimenting for 2 days now, trying al kinds of values. But unfortunately no good results sofar. Any suggestion for a command that would help to stabalize the rope would be great. See the txt file for the entire code.

--box1
box1Body = CreateBodyBox(1,1,1,box1)
box1=CreateCube()
box1:SetParent(box1Body,1)
box1Body:SetPosition(Vec3(0,30,0))
box1Body:SetMass(0)

--some variables
firstBodyCreated = 0
LastBody = nil
       Vec3Pos = Vec3 (0,0,0)
i = 0

--Create more bodies in a loop
for i = 0, 5, i+1 do 
	Vec3Pos = Vec3 (0,i*1.1,0)

	if firstBodyCreated == 0 then
		NewBody = CreateBodyCylinder(0.5,2.5,box1Body)
		firstBodyCreated= 1
	else
		NewBody = CreateBodyCylinder(0.5,2.6,LastBody)
	end

               NewBody:SetMass(10)
               NewBody:SetCollisionType(1,1)
               NewBody:SetPosition(Vec3Pos, 0)
	SetBodyElasticity(NewBody,10)
	NewBody:SetFriction( 5, 5 )

		if LastBody~=nil then
			NewJoint = CreateJointBall (NewBody, LastBody,Vec3 (1, 1, 1))
			SetBallJointLimits (NewJoint, 100,100,100)
		end

               LastBody = NewBody
       end

DebugPhysics(1)
Collisions(1,1,1)

Link to comment
Share on other sites

You might have more luck adding forces to make the nodes of the rope stay a certain distance from one another. You'd have more control that way, and can handle elasticity and breaking, and it's probably less overhead than using joints.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

hmm Sounds more compicated to me. How do you see that going? Something like: The second box is being forced towards the position of the first box, while the first box is pushing the second box away from him?

 

I think I'll try this wiki page first: http://leadwerks.com/wiki/index.php?title=CreateJointBall

 

Also in to old forum I saw a topic where the same joint technique is used

Link to comment
Share on other sites

For each linked pair, take the distance between them, and add force to make them the distance they are supposed to be apart. If you just do this for each pair, it will work itself out and act like a rope.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

What do you mean with 'linked'? Like when linked inside the editor (green line per index)? Because I haven't seen a command in the wiki that can do this by code.

 

The joints are giving me a lot of trouble, so I am gonna try your way now. This is what I have in mind: (according to your way)

  • place 3 boxes under each other
  • each box is parented to the one above (if it exists)
  • a loop checks for the distance between 2 boxes
  • if distance is lower than specified in variable then add force downwards
  • the loop resets the boxes to its previous position, resulting in being pushed away over and over again

I think the adding of forces is going to work as I expect. however, I think that the resetting of the boxes original position is going to cause unwanted results. I'll place back when I have something.

Link to comment
Share on other sites

  • 1 month later...

The technique for this is called spring dampening. You create a "Spring" class that has two vectors or entities, and does the calculation in an Update call to determine the forces to apply. It is then dampened and modified to simulate elasticity, breaking, etc.

 

It is commonly used in 3rd person cameras. I will look for an implementation I have done previously and report back here my findings.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...