which physics joint to move from position A to position B?

Hi,

I’m looking to create a basketball game, which after the player throwing the ball, the ball will hit the wall (point B), and then the ball will then “bounce back” and return to the player position (point A).

in order to throw the ball, I can simply apply the force and physics to it, but how to make the ball return to the fixed point is puzzling me, as I looked through the various physics joints and can’t find any joints that will move the object between point A to point B.

Thanks.

Justin

Hi Justin,

A touch joint would accomplish this. It’s like a “rubber band” which pulls an object toward a specified location, with user-settable force, frequency, and damping.

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

Of course, I should ask, why not just use a transition to move the ball in a straight line back to the starting point? A little in-out easing would make the animation look pretty good, I think.

Brent

Hi Brent,

I was thinking, that the ball will bounce from the basket/wall and drop to the floor, and then bounce back to the user location, so there is still physics apply to the ball and floor, transition.to may not be ideal for such case?

I was trying to figure out how to do it with touch joint and understand how the physics work. In the following example, the main object is the “Red” ball, and I want it to “bounce” to the user location which is the “Green” circle after hitting the floor.

If I activate the touch joint, the Red is basically rotating/orbiting around the Green circle, and don’t know how the Red ball can gradually bounce to position of Green circle?

====

physics = require “physics”

physics.start ()

physics.setGravity( 0, 9.8 )

physics.setDrawMode( “hybrid” )

Red = display.newCircle ( 100, 150, 20)

Red:setFillColor (1, 0, 0)

physics.addBody (Red, “dynamic”, {density = 1, friction = 0, bounce = 1} )

Floor = display.newRect ( 250, 350, 400, 30)

physics.addBody (Floor, “static” )

Green = display.newCircle ( 400, 200, 20)

Green:setFillColor (0, 1, 0)

–touchJoint = physics.newJoint(“touch”, Red, Green.x, Green.y)

======

Thanks,

Justin

Hi Justin,

In that case, I’d consider just applying an impulse to the ball (shortly after it lands on the floor) and send it back toward the player, and then when it collides with the player circle (which should probably be a sensor), you could then transition it to the exact center of that circle, or use a touch joint for the same thing.

Brent

Hi Justin,

A touch joint would accomplish this. It’s like a “rubber band” which pulls an object toward a specified location, with user-settable force, frequency, and damping.

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

Of course, I should ask, why not just use a transition to move the ball in a straight line back to the starting point? A little in-out easing would make the animation look pretty good, I think.

Brent

Hi Brent,

I was thinking, that the ball will bounce from the basket/wall and drop to the floor, and then bounce back to the user location, so there is still physics apply to the ball and floor, transition.to may not be ideal for such case?

I was trying to figure out how to do it with touch joint and understand how the physics work. In the following example, the main object is the “Red” ball, and I want it to “bounce” to the user location which is the “Green” circle after hitting the floor.

If I activate the touch joint, the Red is basically rotating/orbiting around the Green circle, and don’t know how the Red ball can gradually bounce to position of Green circle?

====

physics = require “physics”

physics.start ()

physics.setGravity( 0, 9.8 )

physics.setDrawMode( “hybrid” )

Red = display.newCircle ( 100, 150, 20)

Red:setFillColor (1, 0, 0)

physics.addBody (Red, “dynamic”, {density = 1, friction = 0, bounce = 1} )

Floor = display.newRect ( 250, 350, 400, 30)

physics.addBody (Floor, “static” )

Green = display.newCircle ( 400, 200, 20)

Green:setFillColor (0, 1, 0)

–touchJoint = physics.newJoint(“touch”, Red, Green.x, Green.y)

======

Thanks,

Justin

Hi Justin,

In that case, I’d consider just applying an impulse to the ball (shortly after it lands on the floor) and send it back toward the player, and then when it collides with the player circle (which should probably be a sensor), you could then transition it to the exact center of that circle, or use a touch joint for the same thing.

Brent