Touch Joint

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

So I know this topic is old, but setting the :setScale() helped get the results closer to what I was looking for.

So I know this topic is old, but setting the :setScale() helped get the results closer to what I was looking for.