Touch Joint

Good morning, 

Sorry this is my first post here, I’ve been programming with corona for about a year and a half now, and I was wondering if someone else has come across this problem. I am trying to create a UI that is related to touch joints. However I’ve found that the touch joint is too elastic, I’ve played with all the settings and I can’t get it to respond quickly enough. During the moved phase there’s just way to much of a difference between where the event is happening and where my actual target of the touch joint is. Has anybody else had this problem?

Hi @lofy,

Increasing the “frequency” and “maxForce” should make the touch joint very strong, i.e. the object that follows the touch point should spring to that point very quickly. If this still doesn’t solve it, make sure that the object is not extremely dense or “heavy”.

Here’s the Joints guide for your reference:

http://docs.coronalabs.com/guide/physics/physicsJoints/index.html#touch

Hope this helps,

Brent

So I’ve built a game similar to the Air Hockey example, however if I’m swiping across the screen I’ve found that the joint just isn’t strong enough. When I swipe across the screen the target lags too far behind where the actual event is happening. I have been trying to come up with solutions to reduce the elasticity of the joint but can’t really think of anything.

Please post your code where you set up the physics body (puck) and the touch joint…

playW = _H/1.775*.8

ballR = playW*.04

M.headR = ballR*1

M.players.head = display.newCircle(event.x,event.y, ballR)

physics.addBody( M.players.head,  “dynamic”, { density = 1,filter = headCollisionFilter, radius = M.headR } )

M.players.head.alpha = 1

M.players.head.name = “head”;

M.players.head.isFocus = true

M.players.head.isFixedRotation = true

M.players.head.joint = physics.newJoint( “touch”, M.players.head, M.players.head.x, M.players.head.y )

M.players.head.joint.maxForce = 10000000000000000000000000000000000000000000

M.players.head.joint.dampingRatio = 1

M.players.head.joint.frequency = 1000000000000000000

It responds well enough if I’m not swiping quickly across the screen.

Hi @lofy,

The touch joint might not be ideal for your case. Are you trying to “flick” the puck across the screen? If so, you might want to explore other methods of mimicking that behavior which don’t use the touch joint. I may have some suggestions based on what you’re trying to simulate.

Brent

What other options can I use then? I’m not necessarily trying to flick across the screen as I want the target to stop moving as soon as the touch event has ended. 

Hi @lofy,

You might consider using another physics body which represents the “anchor point” and follows the touch around in lock-step (this object can be invisible but physical). Then, try joining the “puck” to that object using a rope joint. The rope joint will behave like a theoretical rope, and it will prevent the puck from ever separating from the other body by more than the distance of the rope. Of course it will require testing, but theoretically this should make the puck follow the touch faster, and not allow it to drift too far away from it.

Brent

Is the rope joint ready to be used? When I attempted this it functions similar to a distance joint.

Yep, the rope joint definitely works as expected, I’ve tested it myself.

Sorry just strugling with this for some reason, instead of the expected where there would be a small distance between my target and my “head” I had them slowly closing the gap between them and stopping at the maxLength. 

The problem appears that the ropeLength CAN extend beyond its maxLength, however it just recovers back to the maxLength, however if you are swiping quickly across the screen the recover time takes too long.

M.players.headE = display.newCircle(event.x,event.y, ballR)

physics.addBody( M.players.headE,  “dynamic”, { density = 1000000,filter = headECollisionFilter, radius = 10 } )

M.players.head = display.newCircle(event.x,event.y, ballR)

physics.addBody( M.players.head,  “dynamic”, { density = 1,filter = headCollisionFilter, radius = M.headR } )

M.players.head.joint = physics.newJoint( “rope”, M.players.headE, M.players.head )

M.players.head.joint.maxLength = 100

Hi @lofy,

I think you’re going to experience issues no matter what, in the case of a very fast “swipe” with physics and joints. It probably takes one more time-step for Box2D to “catch up” and process the reaction of the joint and the physical forces.

I suppose you could try to detect an extremely fast swipe and just ignore it, letting only “normal” or moderate motions have any effect on the objects.

Brent

Ok, so I’m trying to use applyForce, or setLinearVelocity, to get the “head” to the event.x,y but I feel as if thats too complicated do you have any other ways that you think could be used to solve this problem. I’m sorry but I really can’t just ignore fast swipes, its a bit a part of how I’ve observed people reacting to the game.

Hi @lofy,

Is the idea that the object is essentially under the touch point at any time? Meaning that it follows it exactly? Or does it have to drag just slightly behind?

Brent

I am looking to have it as close to under the touch point at all times, however it needs to be able to interact physically, to be able to hit a “puck” or a “ball”. 

I suppose you could try applying linear velocity (not force) to the puck on each “moved” phase, calculating the X and Y amounts of velocity based on the current position as compared to the previous position. And also set some amount of linear damping on the object, so it slows down on its own when the touch is released.

Brent

Hi @lofy,

Increasing the “frequency” and “maxForce” should make the touch joint very strong, i.e. the object that follows the touch point should spring to that point very quickly. If this still doesn’t solve it, make sure that the object is not extremely dense or “heavy”.

Here’s the Joints guide for your reference:

http://docs.coronalabs.com/guide/physics/physicsJoints/index.html#touch

Hope this helps,

Brent

So I’ve built a game similar to the Air Hockey example, however if I’m swiping across the screen I’ve found that the joint just isn’t strong enough. When I swipe across the screen the target lags too far behind where the actual event is happening. I have been trying to come up with solutions to reduce the elasticity of the joint but can’t really think of anything.

Please post your code where you set up the physics body (puck) and the touch joint…

playW = _H/1.775*.8

ballR = playW*.04

M.headR = ballR*1

M.players.head = display.newCircle(event.x,event.y, ballR)

physics.addBody( M.players.head,  “dynamic”, { density = 1,filter = headCollisionFilter, radius = M.headR } )

M.players.head.alpha = 1

M.players.head.name = “head”;

M.players.head.isFocus = true

M.players.head.isFixedRotation = true

M.players.head.joint = physics.newJoint( “touch”, M.players.head, M.players.head.x, M.players.head.y )

M.players.head.joint.maxForce = 10000000000000000000000000000000000000000000

M.players.head.joint.dampingRatio = 1

M.players.head.joint.frequency = 1000000000000000000

It responds well enough if I’m not swiping quickly across the screen.