Spring effect

I’m trying to use joints to attach an image body to another to give the effect that it is attached via a small spring. The effect should be that when the device is waved about (using the accelerometer to alter the gravity) the image should sort of waggle on the spot (left, right, up and down, maybe a little rotation) but essentially stay where it is.

I thought the friction or weld joints would do the job, but friction doesn’t seem to do anything and I don’t think there’s enough ‘mathmatical approximation’ in the weld to get the right effect. (Thinking about that; do the maxForce and maxTorque values have any effect on the weld joint? I’m guessing not, but guessing…)

Anyone managed to get this effect before?

Thanks,

Matt. [import]uid: 8271 topic_id: 4436 reply_id: 304436[/import]

Have you considered using a targetRotation and targetX and targetY values, which the waggling sprite will follow until it catches them. The idea is that the target values will be repeatedly missed initially because you keep incrementing the force so they shoot out over the goal, which will will cause a swinging/ waggling effect as the sprite tries to return by readjusting the speed again. The key would be to not adjust the coordinates immediately but first adjust the velocity in smaller incremental steps (until a speed limit is reached). In case of a spring you could also apply the targetRotation routine to another joint-connected fixed position object. Admittedly, none of this uses the native physics directly, which is probably what you’re going after (though you can apply both models to the same object)! [import]uid: 10284 topic_id: 4436 reply_id: 13856[/import]

Sorry, but which object provides the targetRotation and targetX and targetY values? I’m a bit lost on what you’re saying, tbh…

matt [import]uid: 8271 topic_id: 4436 reply_id: 13889[/import]

Well, I’m not too sure I did understand the concept right. I imagined this to be like a Jack-in-a-Box, wiggling his head from side to side.

() Jack
|
| Spring
|
() Box

If there’s no spring there and you just want the wiggling, you could apply the speed adjustments to the Jack, or if it’s spring connected, you could rotate the box, and connect it to the Jack with a joint, either way. You would adjust all values indirectly, like with some pseudo code

[blockcode]if rotation < rotationTarget then
rotationSpeed = rotationSpeed + rotationIncrement
elseif rotation > rotationTarget then
rotationSpeed = rotationSpeed - rotationIncrement
end
rotationSpeed = pushIntoLimits(rotationSpeed, -rotationSpeedLimit, rotationSpeedLimit)
rotation = rotation + rotationSpeed
if rotation >= rotationTarget - fuzzy and rotation <= rotationTarget + fuzzy then
rotationSpeed = 0
rotation = rotationTarget
end[/blockcode]

By testing and adjusting your rotationSpeedLimit, your rotationIncrement and the fuzzy value, you can produce different types of wiggle effects. And the very same code works for x and y respectively. Sorry if this is not at all what you’re aiming for, I’m not sure! [import]uid: 10284 topic_id: 4436 reply_id: 13939[/import]

Oh right, sorry - what I meant was as if the jack’s head were viewed from the top.

Or, perhaps, take the spring from the jack-in-the-box, tighten it a bit so its not so springy, fix it to an immoveable plank, then attach a sign to the spring. Then look at the sign on the spring face-on.

In these cases the spring is not actually visible, but the moveable object attached to the top of it is seen to waggle - about as much as a ruler held against the side of a desk and twanged.

I’m intending to produce some test cases with my code, but haven’t got to the point of deploying it to my device yet.

matt [import]uid: 8271 topic_id: 4436 reply_id: 13958[/import]

Oh right, sorry - what I meant was as if the jack’s head were viewed from the top.

Yes that’s how I intially understood it too, above code suggestion was meant to work for that as well (though it may only be an approximation of what you’re going for, I’ve used this approach a lot in my stuff but never tried how it fares with the “twanged ruler” effect you want to go for).
[import]uid: 10284 topic_id: 4436 reply_id: 13961[/import]

Cool, thanks, I’ll give it a bash :slight_smile: [import]uid: 8271 topic_id: 4436 reply_id: 13963[/import]