Big error crashes simulator

Hi,

I’ve got some square png’s which move down the screen in a column as sensors, using a transition. When the bottom image collides with a platform I cancel and remove the transition and switch the sensors off. I then have a loop which tries to set the y value of each image to place each one sitting directly on top of the one below. I do this because I want the blocks to move down the screen at a regular speed, touch the platform (which could be at any height) and stop immediately, Tetris-style.

I’m using the physics engine because the maths involved with the platform motion etc was killing me. I’m open to suggestions.

My problem is that while everything works fine, when the images collide with the platform, at the point of turning off the transition they bounce back up a little. I have friction, bounce and density all set to 0.0.

I tried putting in a loop to set the y position when they land, but it caused this exception:

Assertion failed: (m_world->IsLocked() == false), function SetTransform, file /Users/ansca/.hudson/jobs/Pong-DMG/workspace/platform/mac/…/…/external/Box2D_v2.1.2/Box2D/Box2D/Dynamics/b2Body.cpp, line 395.
/Applications/Corona Game Edition Beta/Corona Terminal: line 9: 4955 Abort trap “$path/Corona Simulator.app/Contents/MacOS/Corona Simulator” $*

I guess the easy answer, if anyone knows it, would be how to make blocks move down the screen until they collide with something, then become stationary objects on a platform.

Thanks,

matt. [import]uid: 8271 topic_id: 2022 reply_id: 302022[/import]

After some playing, I see that turning gravity off stops the bounce effect seen when the blocks hit the bottom/platform. Problem is, I need the gravity… [import]uid: 8271 topic_id: 2022 reply_id: 5935[/import]

Why do you need gravity?

Also isnt there a function to process a command before the collision happens. At that point your function can shut off the collision and position the block correctly [import]uid: 5354 topic_id: 2022 reply_id: 5941[/import]

I need the gravity for blocks which have already landed.

What do you mean by “shut off the collision”? I’ve tried simply cancelling the transition and placing the block to be still, but it acts as though the block below is slightly squashy or resists the collision. [import]uid: 8271 topic_id: 2022 reply_id: 5943[/import]

@horacebury – if you set bounce to zero on the blocks AND the platform, you shouldn’t get any bounce. I just tested this now in the “HelloPhysics” code:

local physics = require( "physics" )  
physics.start()  
  
local sky = display.newImage( "bkg\_clouds.png" )  
  
local ground = display.newImage( "ground.png" )  
ground.x = 160; ground.y = 445  
  
physics.addBody( ground, "static", { friction=0.5, bounce=0 } )  
  
local crate = display.newImage( "crate.png" )  
crate.x = 180; crate.y = -50  
  
physics.addBody( crate, { density=3.0, friction=0.5, bounce=0 } )  

In general, you may want to avoid using transitions on a dynamic physics object, since on every frame you’re fighting what the engine is trying to do. However, the crash you’re seeing is a bug that we’d like to fix – can you zip your project and send it to support@anscamobile.com ? Mention bug 1181 if you can, but either way, this would help. [import]uid: 3007 topic_id: 2022 reply_id: 6555[/import]

Hi evank,

Thanks for you reply - I did in fact set the friction and bounce to 0 in the end. I ended up realising that the transition is probably the wrong way to go and started playing with a lot of physics values. The combination that worked was simply to set the linearDamping value to get a constant motion down the screen without using a transition.

I’m afraid that I’ve forgotten how I got round the exception, but I think it was caused by trying to modify a physics object within the event handler of it’s own collision listener. Is this fixed in the latest GE release or did I just learn enough not to encounter it? I notice that it is possible to remove a collision listener from within it’s own handler, now.

matt

Ps: Sorry for the late reply, I hadn’t noticed this had gotten a reply in the torrent of posts I’ve been making recently. [import]uid: 8271 topic_id: 2022 reply_id: 7545[/import]