issues balls sticking to rotating platform

Hi,

I am having issues with balls sticking to a rotating platform. I tried to change the friction, density, etc… to the balls and the platform and have had no luck. Does anyone have a fix for this?

Thanks in advance

local beam2 = display.newImage( “images/beam2.png” )
beam2.x = 150; beam2.y = 250
physics.addBody( beam2, “static”, { density=100, friction=0, bounce=.3 } )
localGroup:insert(beam2)

local function rotate( event )
beam2.rotation = beam2.rotation + 1
end
Runtime:addEventListener( “enterFrame”, rotate ) [import]uid: 33363 topic_id: 6677 reply_id: 306677[/import]

Anybody have a solution to this? Thanks [import]uid: 33363 topic_id: 6677 reply_id: 23684[/import]

What do you want to do with the ball? if you want the ball to subject to gravity then you can change the physics bodytype to
“dynamic”.

like this:

[lua]local beam2 = display.newImage( “images/beam2.png” )
beam2.x = 150; beam2.y = 250
physics.addBody( beam2, “dynamic”, { density=100, friction=0, bounce=.3 } ) – new code
localGroup:insert(beam2)

[import]uid: 12455 topic_id: 6677 reply_id: 23841[/import]

I am having the same problem. The issue with making it dynamic is then it falls due to gravity.

This is my code. It rotates, but again things stick to it. I’ve even tried zero friction.

local board1 = display.newImage( "images/board.png" )  
board1.x = 265; board1.y = 150; board1.rotation = 0  
board1:scale( .5, .5 )  
physics.addBody( board1, "static", { friction=0 } )  
localGroup:insert(board1)  
  
local function rotate( event )  
board1.rotation = board1.rotation + 1  
end  
Runtime:addEventListener( "enterFrame", rotate )  

Any ideas? [import]uid: 32061 topic_id: 6677 reply_id: 26047[/import]

I have tried everything I can think of and falling balls hitting rotating platforms act wrong. They stick when they should roll down and then when they should fall with gravity, they shoot off.

Is it a corona glitch. [import]uid: 32061 topic_id: 6677 reply_id: 26056[/import]

Carlos! help please. Anyone. Same problem here. [import]uid: 42779 topic_id: 6677 reply_id: 26301[/import]

Yes help us, i have also exactly same problem. [import]uid: 18445 topic_id: 6677 reply_id: 26346[/import]

Yes please help I have same problem and regardless if
I change the bounce friction ect nothing seems to help
out. [import]uid: 30314 topic_id: 6677 reply_id: 26363[/import]

I had a very similar problem in my game. I don’t think given the way Corona is built that there is a physics-friendly way around this issue (i.e. stopping the platform from falling AND making it collide properly).

What I decided to do was to set the rotating platforms to dynamic to ensure collisions worked properly, and in the enterFrame event I reset the x,y coordinates of the platform. That way the platform will collide properly, will rotate properly, and each frame when gravity calculates it dropping, you set it’s position back up to where it should be and the player will not see the movement. [import]uid: 36054 topic_id: 6677 reply_id: 26623[/import]

Thanks. Will you post the code? [import]uid: 42779 topic_id: 6677 reply_id: 26676[/import]

Sure, here’s a quick example (assume physics is initiated with any values you desire) – my own code is a bit too mathematical and would get in the way of understanding at this point.

line = display.newRect(0,0, 100, 10)
physics.addBody(line, “dynamic”, {density=1, friction=1, bounce=1})
line.x = 200
line.y = 200
line.rotation = 0

local function enterFrame( event )
line.rotation = line.rotation + 1
line.x = 200
line.y = 200
end

Runtime:addEventListener(“enterFrame”, enterFrame)
[import]uid: 36054 topic_id: 6677 reply_id: 26678[/import]

I added it, but now the balls touch the rotating platform, vibrate a second, and then go right through it?

Have I over simplified it? Thanks for your help.

local beam2 = display.newImage( "images/beam2.png" )  
beam2.x = 150; beam2.y = 250  
physics.addBody( beam2, "dynamic", { density=1, friction=1, bounce=1 } )  
localGroup:insert(beam2)  
  
local function rotate( event )  
beam2.rotation = beam2.rotation + 1  
beam2.x = 150  
beam2.y = 250  
end  
Runtime:addEventListener( "enterFrame", rotate )   

[import]uid: 42779 topic_id: 6677 reply_id: 26695[/import]

You got it exactly right, it is my code that’s out of control. I missed some things in my sea of collapsed functions…

You will need to add all of this too when you instantiate the object (i.e. just don’t put it in the rotate function):

  
local function lineCollision( self, event )  
 if event.phase == "begin" then  
 self.bodyType = "static"  
 end  
end   
  
local function postLineCollision( self, event )  
 self.bodyType = "dynamic"  
end  
  
line.collision = lineCollision  
line:addEventListener("collision", line)  
line.postCollision = postLineCollision  
line:addEventListener("postCollision", line)  
  

This problem is more annoying than I remembered :frowning: [import]uid: 36054 topic_id: 6677 reply_id: 26699[/import]

One more note, density can make a big difference, go read up on it! [import]uid: 36054 topic_id: 6677 reply_id: 26704[/import]

Still having the same problem. The objects go right through it.

[code]
local beam2 = display.newImage( “images/beam2.png” )
beam2.x = 150; beam2.y = 250
physics.addBody( beam2, “dynamic”, { density=100, friction=1, bounce=1 } )
localGroup:insert(beam2)

local function rotate( event )
beam2.rotation = beam2.rotation + 1
beam2.x = 150
beam2.y = 250
end
Runtime:addEventListener( “enterFrame”, rotate )

local function lineCollision( beam2, event )
if event.phase == “begin” then
beam2.bodyType = “static”
end
end

local function postLineCollision( beam2, event )
beam2.bodyType = “dynamic”
end

beam2.collision = lineCollision
beam2:addEventListener(“collision”, beam2)
beam2.postCollision = postLineCollision
beam2:addEventListener(“postCollision”, beam2)
[/code] [import]uid: 42779 topic_id: 6677 reply_id: 26734[/import]

Sorry, but I think you guys are going about this completely the wrong way. In my game I’ve got a platform acting as a see-saw - rotating and allowing things to hit it, with no problems.

Your issue is that you’re trying to make the dynamic platform stay in place by using absolute position in the enterFrame event, which has been pointed out in previous threads as working against the physics engine.

What you should do is pivot the platform against a static body using the pivot joint. The static body can’t move and the pivot joint will hold the dynamic body in relative place.

Here’s some code to do that:

[lua]-- enable physics engine
local physics = require(“physics”)
physics.start()

– enable physics engine
require(“physics”)
physics.start()

– create an invisible, static body as the “anchor”
local anchor = display.newCircle( -100, -100, 10 )
physics.addBody( anchor, “static” )

– create and position the dynamic platform
local platform = display.newImage( “platform.png” )
platform.x, platform.y = display.contentCenterX, display.contentCenterY
physics.addBody( platform, “dynamic”, { friction=1, bounce=.2 } )

– create a pivot to join the anchor to the platform
local pivot = physics.newJoint(
“pivot”, – joint type
anchor, platform, – objects to join together
platform.x, platform.y – physics world location to join at
)

– you may want to limit the spinning by ‘damping’ the rotation
platform.angularDamping = 5[/lua]

Now, if you put that into a code sample with, for example, crates dropping to the ground, they should bounce off a rotating platform.

Here’s the docs for a description of how to use the joints:

http://developer.anscamobile.com/content/game-edition-physics-joints#Pivot_joint

Matt. [import]uid: 8271 topic_id: 6677 reply_id: 26751[/import]

It Works! Thanks! [import]uid: 32061 topic_id: 6677 reply_id: 26827[/import]

horacebury, thanks for this code! Works great.

Now, what I want to try and do is have some control over the dynamic platform. i.e. whilst I want physics and other objects to be able to effect it, I also want to have a ‘left’ button and a ‘right’ button that can make it rotate more to the left or more to the right.

Perhaps I need to control the pivot joint itself…

Is this possible?

I’m new here so sorry if it is actually really simple to do.
Thanks so much,
M [import]uid: 42777 topic_id: 6677 reply_id: 26949[/import]

Well, I suppose you could use the motor, but that requires that you know how much force you need to apply to counteract the other body forces working against the platform.

I have this situation in my game also and the solution I found was to use a transition.to to adjust the rotation property of the object.

Just be careful, however, as this can sometimes produce an effect where the object gets removed from the world but it’s reference does not, so if you are not careful you might see the object disappear while your code accessing it’s values and functions continue to work. My solution to that issue was simply to set the rotation property only once every 4 seconds.

You would probably be better using a touch point in the enterFrame event to control it’s rotation precisely, but that is not graceful, so I don’t like it. I’m not honestly sure what a good, reliable solution is. The problem is that the physics functions should be used when controlling physics objects - setting values like x and y on a regular frequency is fighting the physics engine and will cause problems. [import]uid: 8271 topic_id: 6677 reply_id: 26970[/import]

I see. Thanks for your reply.

Sorry to be thick, but can you explain a ‘transition.to to adjust the rotation property of the object’… and how can I use this?

Perhaps I could have a touch event on one button that increases the rotation (right) and a touch event on another button that decreases the rotation (left)… using this transition you mention.

Really grateful if you have any ideas how to do this. (I’m new and still learning).

Thanks! [import]uid: 42777 topic_id: 6677 reply_id: 26978[/import]