Create Fixed position Object (like stone)

Also, I just looked at your screenshot and the bodies are square and too small.

The size issue is a side-effect of scaling + newImage() + physics bodies.  You’d be better off doing this:

( MAY CONTAIN TYPOS )

local physics = require "physics" physics.start() physics.setGravity( 0, 0 ) physics.setDrawMode( "hybrid" ) local img1=display.newImageRect( "sun.png", 100, 100 ) img1.x = display.contentCenterX img1.y = display.contentCenterY physics.addBody(img1,"static", { radius = 50 } ) local img2=display.newImageRect( "moon.png", 100, 100 ) img2.x = display.contentCenterX - 20 img2.y = 0 physics.addBody(img2,"dynamic", { radius = 50 } ) img2.isFixedRotation = true img2.touch = function( self, event ) if( event.phase == "began" ) then local dy = display.contentHeight - self.y self:setLinearVelocity( 0, dy/10 ) self:removeEventListener("touch") end end img2:addEventListener( "touch" )

is there any function to setTarget position with physics?
I just saw joint touch that has setTarget function ,but i can not use it in my situation.

No, there is not.

Hi @arash45654,

You can move physical objects using transitions, but you need to be careful with how you handle it, otherwise you’ll encounter complications of the two “systems” not know what the other one is doing (which is sort of what @roaminggamer is eluding to).

See here for some details on this:

https://docs.coronalabs.com/guide/physics/limitations/index.html#transitions

Brent

There are a couple of things going on here.

First and foremost, when you scale an object, physics doesn’t scale with it. In this case, your display objects are twice the size of the physics body. Secondly you are letting the bodies default to a square.  You probably should consider setting the bodies to be a circle at which point you can specify the radius to be the size you really want it to be.  You’re setting the width/height to 50 then doubling the size to 100. Why not just set it to 100 to begin with? Regardless you can do:

physics.addBody( img1, { radius=50 } )

to make it a 100px wide circle. Then you are using a non-physics way of moving the bodies. transition.to doesn’t know about physics, so it just moves the objects. If you have a collision listener setup, it should generate a collision, but you’re not allowing physics to control the body movement so they will overlap.

Rob