Tentacles. Problems with "pivot" joints. Need a solid rope!

So i’m trying to create 8 nasty tentacles for my monster and having a fair bit of trouble doing so. I gather box2D doesn’t do ropes very well?? I’m new to tables and loops but learning a lot fast. I’ve hacked over some code from the bridge example and got 8 arms, made up of 16 segments. The segments still like to spin around a bit and that is something I’d like to get under control. Also I would like to have each arm react to a small applyForce on a timer to make them seem a bit more life like. I can do this if I make one but I am having trouble doing it for individual ones created in my loop. Check it out. Any suggestions guys?? I’m thinking that I can also constrain the pivot rotation.

[lua] tentacle = {}
tentacleJoint = {}
tentacleCollisionFilter = { groupIndex = -2 }

playerXJoint = player.x + 25

for i = 1,8 do

for j = 1,16 do

tentacle[j] = display.newImage( “tentacle.png” )
tentacle[j].x = playerXJoint + (j*4)
tentacle[j].y = player.y + (i - 5)
tentacle[j].rotation = 100
tentacle[j].angularDamping = 1000

physics.addBody( tentacle[j], { density=3, friction=1, bounce=0.3, filter = tentacleCollisionFilter } )

if (j > 1) then
prevLink = tentacle[j - 1]
else
prevLink = player
end

nextLink = tentacle[j]

tentacleJoint[j] = physics.newJoint( “pivot”, prevLink, nextLink, playerXJoint + (j*4), player.y + (i - 5) )

end

tentacle[10]:applyForce(1, -1)

end[/lua]

At the moment that applyForce hits all the arms at once. [import]uid: 26289 topic_id: 15580 reply_id: 315580[/import]

Ok, I have made quite a bit of progress. The only thing that is holding me back now is the elasticity of the arms/tentacles.

They are too stretchy. So when the monster moves, it’s arms stretch half way across the screen before catching up.

Does anyone know a way to make the joints ‘weld’ better; or make the arms less stretchy.
Much Appreciated

Here is my new code

[lua]tentacle = {}
longTentacle = {}
sucker = {}
suckerJoint = {}
tentacleJoint = {}
longTentacleJoint = {}
tentacleCollisionFilter = { groupIndex = -2 }

playerX = player.x + 20
playerXJoint = player.x + 17

for i = 1,8 do

for j = 1,16 do

tentacle[j] = display.newImage( “tentacle.png” )
tentacle[j].x = playerX + (j*4)
tentacle[j].y = player.y + (i - 7)
tentacle[j].rotation = 100
tentacle[j].angularDamping = 1000

physics.addBody( tentacle[j], { density=3, friction=1, bounce=0.3, filter = tentacleCollisionFilter } )

if (j > 1) then
prevLink = tentacle[j - 1]
else
prevLink = player
end

nextLink = tentacle[j]

tentacleJoint[j] = physics.newJoint( “pivot”, prevLink, nextLink, playerXJoint + (j*4), player.y + (i - 7) )
tentacleJoint[j].isLimitEnabled = true
tentacleJoint[j]:setRotationLimits( -10, 10 )
end

tentacle[4]:applyForce(1,1)
tentacle[8]:applyForce(-1,-1)

end

for i = 1,2 do

for h = 1,25 do

longTentacle[h] = display.newImage( “tentacle.png” )
longTentacle[h].x = playerX + (h*4)
longTentacle[h].y = player.y + (i - 7)
longTentacle[h].rotation = 100
longTentacle[h].angularDamping = 1000

physics.addBody( longTentacle[h], { density=3, friction=1, bounce=0.3, filter = tentacleCollisionFilter } )

if (h > 1) then
prevLink = longTentacle[h - 1]
else
prevLink = player
end

nextLink = longTentacle[h]

longTentacleJoint[h] = physics.newJoint( “pivot”, prevLink, nextLink, playerXJoint + (h*4), player.y + (i - 7) )
longTentacleJoint[h].isLimitEnabled = true
longTentacleJoint[h]:setRotationLimits( -10, 10 )
end

suckerJointX = player.x
suckerJointY = player.y - 5

for s = 1,2 do

sucker[s] = display.newImage( “sucker.png”)
sucker[s].x = suckerJointX + 125
sucker[s].y = suckerJointY
–sucker[s].rotation = 100
sucker[s].angularDamping = 1000

physics.addBody( sucker[s], { density=3, friction=1, bounce=0.3, filter = tentacleCollisionFilter } )

suckerJoint[s] = physics.newJoint( “pivot”, longTentacle[25], sucker[s], suckerJointX + 122, suckerJointY )
suckerJoint[s].isLimitEnabled = true
suckerJoint[s]:setRotationLimits( -10, 10 )
end

longTentacle[4]:applyForce(1,1)
longTentacle[8]:applyForce(-1,0)

end[/lua] [import]uid: 26289 topic_id: 15580 reply_id: 57552[/import]

Hi CELL,

i think this nice post by HETAL will help you

http://blog.anscamobile.com/2011/06/the-secret-wheels-of-an-app-guest-post-by-mudstuffing/

BR,
Alen [import]uid: 9592 topic_id: 15580 reply_id: 57568[/import]

@Alen, I’ve read that and while it’s nice to know it can be done, i don’t think it actually offers a technical solution for my current problem. It’s more to do with avoiding the arms getting stuck in the physical environment and thinking up workarounds for bugs. A great article nonetheless.

I’m going probably going to implement it in my code anyway so who knows it might have the added side effect of fixing my problem.

Cheers Alen [import]uid: 26289 topic_id: 15580 reply_id: 57569[/import]

I’m working on tentacles as well and had the same stretchy segments problem. Limiting the joint rotation did not help much at all, but here’s what did.

I have a tentacle with 10 segments that taper toward the end. When I joint them where you would normally think to it stretches badly. What I did was used 20 segments instead, repeating each segment once and jointing them at half the height of the previous so they overlap. So each of my 10 segments is really 2 overlapping segments. This seems to “pack” it together more and I don’t have the stretchy problem. Also increasing the density of the segments helps too.
[import]uid: 40137 topic_id: 15580 reply_id: 57597[/import]

Also, I don’t know how you have the tentacles set up, but mine are attached to a monster’s body and I’ve found that applying a small force to the body of the monster rather than the tentacles gives it a more lifelike appearance. If yours are tentacles “coming out of the walls” so to speak, you might try creating some kind of anchor for each tentacle and applying the force to the anchor. [import]uid: 40137 topic_id: 15580 reply_id: 57604[/import]

Thanks mmathias6410 thats a great idea! I’ll give it a whirl and let you know how I get on.

Cheers

Cell [import]uid: 26289 topic_id: 15580 reply_id: 57666[/import]

@ mmathias6410 Man this problem is a tricky one. Just out of curiosity, my tentacles are attached to a moving object that can be moved around the screen. When it moves, the tentacles stretch. Was this a similar problem to yours? [import]uid: 26289 topic_id: 15580 reply_id: 57683[/import]

I have both. One that moves around the screen and one that is fixed but rotates. The biggest problem is that in order to minimize the stretch you have to ramp up the density of the individual segments. This of course makes the entire tentacle extremely heavy and if the monster and tentacles start moving too fast, inertia takes over and it goes all crazy stretchy. To combat this I upped the friction of each segment as well and so far that has worked. The result is a slow moving monster, but that works for my purposes.

I use a timer rather than an enterFrame event to check for either a minimum angular or linear velocity depending if the monster is fixed or free roaming. If it falls below the minimum it gets a random impulse to keep it going.

I seriously considered ditching the physics and using animations and more math, but 1) the monster is not a huge part of the game, and 2) the kind of random/lifelike movement I get on the tentacles with physics is way beyond anything I could animate.

Not sure if this helps, but if you’ve packed the segments down tighter and you’re still getting stretch you probably need some combo of higher density, higher friction, and less speed. [import]uid: 40137 topic_id: 15580 reply_id: 57773[/import]

Sorry, I just looked back at your code and saw your segments have a density of 3. My segments are 16x12 (the physics area is somewhat smaller) and each has a density of 200. 3 will give you stretchy. [import]uid: 40137 topic_id: 15580 reply_id: 57783[/import]