Thank you so much for a lot of help.
I want to push that ball.like this
roaminggamer:
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 } )
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.