How to change dimensions of object in the physics engine

Hello Guys,

How to change dimensions of objects in the physics engine.

as you can see in the below GIF. I want to push that ball.

I had read in docs that we can’t use transition in the physics engine.Is there any other approach to do this

local \_W = display.actualContentWidth local ball = display.newCircle(centerX-80,centerY-100,20) physics.addBody(ball) local pipe = display.newRect( 0, 0, 20, 10 ) physics.addBody(pipe,"static") local button = display.newCircle( 0,0,20 ) button:setFillColor( 1,0,0 ) function movePipe( ) transition.to( pipe.path, { time=6000, x1=-\_W ,x2=-\_W} ) end function moveObj( event ) if(movement == false) then print( "ON" ) movePipe() else print( "OFF " ) end end button:addEventListener( "tap", moveObj )

I think the use of the word dimensions is confusing here.  

Are you asking how to move physics objects or resize their bodies?

If the latter, you can’t.  i.e. You can’t resize physics bodies.

If the prior, you can use a touch joint hack to pull the object.

Dimension is shape and size, whereas I think you meant position.

Do you simply want to click and have that cause the object on the right to move till the click is released?

Sorry, but please elaborate more on what moves when as related to touching the screen and then lifting your finger.

Also, do we have to touch the object you want to move or anywhere on the screen.

Are you trying to extrude something from the object on the right and have that ‘extruded entity’ push the object on the left?

Sorry for playing 20 questions here.  You supplied a picture (which is great) and I’m still not quite sure what you want.  :frowning:

Try this: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/03/pusher.zip

Not perfect but OK.

https://www.youtube.com/watch?v=Knn9sliHIS4&feature=youtu.be

PS - Your code as pasted didn’t run after cut-copy-pasting.  Please be sure we can run pasted code if you want faster help.

io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) -- ===================================================== -- ===================================================== local centerX = display.contentCenterX local centerY = display.contentCenterY local fullw = display.actualContentWidth local fullh = display.actualContentWidth -- local physics = require "physics" physics.start() physics.setGravity(0,0) physics.setDrawMode("hybrid") -- -- GROUND local ground = display.newRect( centerX, centerY + 60, 1000, 40 ) physics.addBody(ground,"static", { bounce = 0, friction = 1 }) ground:setFillColor(0,0.8,0) ground.friction = 0.5 -- BALL local ball = display.newCircle( centerX, centerY, 40 ) physics.addBody(ball, { bounce = 0, friction = 1 }) ball:setFillColor(0,1,1) ball.isSleepingAllowed = false ball.linearDamping = 2 -- PIPE & PUSHER local pipe = display.newRect( centerX + 140, ball.y, 80, 20 ) pipe.anchorX = 1 pipe:setFillColor(1,0,0) -- local pusher = display.newRect( pipe.x - pipe.width, pipe.y, 10, 20 ) pusher.anchorX = 0 pusher:setFillColor(1,1,0) pusher.myPipe = pipe physics.addBody(pusher, { bounce = 0, friction = 1 }) pusher.isSleepingAllowed = false pusher.isFixedRotation = true pusher.touchJoint = physics.newJoint( "touch", pusher, pusher.x, pusher.y ) --pusher.isVisible = false pusher.touchJoint.maxForce = 1e6 pusher.touchJoint.frequency = 1e9 pusher.touchJoint.dampingRatio = 0 local ox = 2 -- transition leads position, so offset a little function pusher.enterFrame( self ) local pipe = self.myPipe local joint = self.touchJoint joint:setTarget( pipe.x - pipe.width - ox, pipe.y ) end; Runtime:addEventListener( "enterFrame", pusher) local tx = - 200 transition.to( pipe.path, { time = 3000, x1 = tx , x2 = tx } )

I can think of a way to make this push smoothly, but in reality it will be a temporary touch joint pulling the ‘contacted’ object.

It has a lot of the same code, but things are switched around logically, and a collision listener is included.

Also, at that point, the ‘pusher’ can be a sensor.

I’ll leave that to you as an exercise if you need it to be smoother.

Last post, finally you should investigate the joints.  There may be another answer in there just waiting to be found.

https://docs.coronalabs.com/api/library/physics/newJoint.html

https://docs.coronalabs.com/guide/physics/physicsJoints/index.html

https://docs.coronalabs.com/guide/physics/physicsJoints/index.html#piston

Yes

Thank you so much for a lot of help.

I want to push that ball.like this

thank you so much for the code. It’s a little bit difficult to understand to me.

as per my understanding, in this code creating new pipes & attaching it to previous one.

I got how your code works.

In this code, you are changing the shape of pipe using trasition.to

& by touch joint shifting the pusher to the new position 

If the latter, you can’t.  i.e. You can’t resize physics bodies.

Why? How about a… ball? By scenario this ball is increasing it’s size (radius) 2x in time of 10 seconds and by scenario all this time this ball must react on other bodies. How can this be done? By removing it from physics + resizing + adding in physics colletion each frame?

Ok, Ill help you to imagine this: a monster (physic body, is standing on platform, pushing balls, platforms) grows on each bullet you hit in him. Any ideas?

You can’t change the size of a physics body PERIOD.  You can only replace it.

I don’t have any good answers for you.  This something I simply never do.

Tip: You’d be better off starting a new thread or marking this not solved. 

Adding more questions to a  thread marked as solved is unlikely to get many responses.

I think the use of the word dimensions is confusing here.  

Are you asking how to move physics objects or resize their bodies?

If the latter, you can’t.  i.e. You can’t resize physics bodies.

If the prior, you can use a touch joint hack to pull the object.

Dimension is shape and size, whereas I think you meant position.

Do you simply want to click and have that cause the object on the right to move till the click is released?

Sorry, but please elaborate more on what moves when as related to touching the screen and then lifting your finger.

Also, do we have to touch the object you want to move or anywhere on the screen.

Are you trying to extrude something from the object on the right and have that ‘extruded entity’ push the object on the left?

Sorry for playing 20 questions here.  You supplied a picture (which is great) and I’m still not quite sure what you want.  :frowning:

Try this: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2018/03/pusher.zip

Not perfect but OK.

https://www.youtube.com/watch?v=Knn9sliHIS4&feature=youtu.be

PS - Your code as pasted didn’t run after cut-copy-pasting.  Please be sure we can run pasted code if you want faster help.

io.output():setvbuf("no") display.setStatusBar(display.HiddenStatusBar) -- ===================================================== -- ===================================================== local centerX = display.contentCenterX local centerY = display.contentCenterY local fullw = display.actualContentWidth local fullh = display.actualContentWidth -- local physics = require "physics" physics.start() physics.setGravity(0,0) physics.setDrawMode("hybrid") -- -- GROUND local ground = display.newRect( centerX, centerY + 60, 1000, 40 ) physics.addBody(ground,"static", { bounce = 0, friction = 1 }) ground:setFillColor(0,0.8,0) ground.friction = 0.5 -- BALL local ball = display.newCircle( centerX, centerY, 40 ) physics.addBody(ball, { bounce = 0, friction = 1 }) ball:setFillColor(0,1,1) ball.isSleepingAllowed = false ball.linearDamping = 2 -- PIPE & PUSHER local pipe = display.newRect( centerX + 140, ball.y, 80, 20 ) pipe.anchorX = 1 pipe:setFillColor(1,0,0) -- local pusher = display.newRect( pipe.x - pipe.width, pipe.y, 10, 20 ) pusher.anchorX = 0 pusher:setFillColor(1,1,0) pusher.myPipe = pipe physics.addBody(pusher, { bounce = 0, friction = 1 }) pusher.isSleepingAllowed = false pusher.isFixedRotation = true pusher.touchJoint = physics.newJoint( "touch", pusher, pusher.x, pusher.y ) --pusher.isVisible = false pusher.touchJoint.maxForce = 1e6 pusher.touchJoint.frequency = 1e9 pusher.touchJoint.dampingRatio = 0 local ox = 2 -- transition leads position, so offset a little function pusher.enterFrame( self ) local pipe = self.myPipe local joint = self.touchJoint joint:setTarget( pipe.x - pipe.width - ox, pipe.y ) end; Runtime:addEventListener( "enterFrame", pusher) local tx = - 200 transition.to( pipe.path, { time = 3000, x1 = tx , x2 = tx } )

I can think of a way to make this push smoothly, but in reality it will be a temporary touch joint pulling the ‘contacted’ object.

It has a lot of the same code, but things are switched around logically, and a collision listener is included.

Also, at that point, the ‘pusher’ can be a sensor.

I’ll leave that to you as an exercise if you need it to be smoother.

Last post, finally you should investigate the joints.  There may be another answer in there just waiting to be found.

https://docs.coronalabs.com/api/library/physics/newJoint.html

https://docs.coronalabs.com/guide/physics/physicsJoints/index.html

https://docs.coronalabs.com/guide/physics/physicsJoints/index.html#piston

Yes