Object Drops, Collision then...

Hey!

Im very new to Corona, but have picked up a ton by watching the YouTube videos and tutorials - however - I am running into what I think would be a very simple operation for Corona/Lua.

I have an image that drops for a “y” screen location and collides with another object. I want to be able to have these two objects - at that point - be joined to each other. Real World Example: Lets say I have a book in my hand and I drop another book from 5-10 inches. When the dropped book hits the book Im holding it stays there and I can try to stack another book. Seems simple, but in Corona - I can get the book to fall and also have it hit the book I’m holding, but when I move the book I’m holding the other just falls with gravity.

Please help me out with this as I have struggled to find a solution that makes any sense to me.

THANKS A TON!!!

Todd [import]uid: 53789 topic_id: 9234 reply_id: 309234[/import]

Hmm… I haven’t done anything like that before, but you might want to look up physics joint if you’re dealing with physics.

if you’re doing joint then when the two objects collide, you’ll create a pivot joint at the collision point. Again, I haven’t done anything like that so I’m just guessing where I will begin. [import]uid: 12455 topic_id: 9234 reply_id: 33687[/import]

What you might try is erasing both objects on collision and then create a joined object at the point of collision. [import]uid: 10903 topic_id: 9234 reply_id: 33737[/import]

Can you give me a little code example of what that would look like. I mean I keep hearing that you cant mess with the physics of a object in a collision function. I think this is where I’m getting messed up - I just don’t understand how to do what you’ve explained.

This is what I have and is crashes corona…

local function onLocalCollision( self, event )
if ( event.phase == “began” ) then

myJoint = physics.newJoint( “touch”, self, event.other, event.x, event.y )

elseif ( event.phase == “ended” ) then

– I’ll add something later…

end
end


Any help would be greatly appreciated!!! Thanks guys!!

Todd [import]uid: 53789 topic_id: 9234 reply_id: 33752[/import]

I would do something like this.

The crash is probably happening because your creating a physics object on collision, which might be a bug. The work around is to delay the creation of a physics object with a timer, check my collision.

[code]

local physics = require(“physics”)
physics.start()
physics.setGravity( 0, 9.8 )

local storex, storey

local box1 = display.newRect(150,100,50,50)
physics.addBody(box1, { density=0.3, friction = .5})

local box2 = display.newRect(150,300,50,50)
physics.addBody(box2, “static”, { density=0.3, friction = .5})

function create3()
local box3 = display.newRect(storex-32,storey-32,75,75)
physics.addBody(box3, { density=0.3, friction = .5})
end

function onCollision( event )
if ( event.phase == “began” ) then
local doCollision = function()
print(“hit”)
if (event.object1 ~= nil and event.object2 ~= nil) then
storex = event.object2.x
storey = event.object2.y
event.object1:removeSelf()
event.object2:removeSelf()
create3()
end
end
local collisionTimer = timer.performWithDelay( 0, doCollision, 1 )
end
end

Runtime:addEventListener( “collision”, onCollision )

[/code] [import]uid: 10903 topic_id: 9234 reply_id: 33766[/import]

Hey - The above code works great - for creating one new object.

what I was able to do in create3 - is to make the new “books” if you will - on top of each other as they collide - and now I want to join them. Whenever I do a join - I get the following:
Heres the function:

36: function create3()
37: local Lgbook1 = NewLgBook()
38: local SmBook1 = NewSmSquare()
39: myJoints = physics.newJoint( “pivot”, Lgbook1, SmBook1, storex, storey )
40: end

ERROR: table expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
[C]: ?
[C]: in function ‘newJoint’
/Users/Desktop/main.lua:39: in function ‘create3’
/Users/Desktop/main.lua:91: in function ‘_listener’
?: in function <?:441>
?: in function <?:214>

Line 91 is the call to create3()
[import]uid: 53789 topic_id: 9234 reply_id: 33788[/import]

I don’t know joints at all, but it looks like from the error that it thinks you want to add myjoints to a table, so it’s probably just an issue with the newjoint syntax. [import]uid: 10903 topic_id: 9234 reply_id: 33794[/import]

You were right - I did that and it worked - with the joints. One of the problems is - is that I lose the “physics” characteristics of the object - when do a “weld” joint. The other joints do not work that well.

Imagine stacking 6 boxes on top of each other and trying to balance them - when you move the bottom box in Corona - it moves, but the others do nothing unless you get to the side where they will fall off the box. I WANT THAT, but you would think that the boxes - based on weight and gravity - would go along for the ride of the box under it. Am I doing something wrong here or is my thinking not right in Corona?

Any help on this matter would be GREATLY appreciated… This can’t be the first time someone has dealt with this issue, i’m sure…

Thanks again!!!

Todd [import]uid: 53789 topic_id: 9234 reply_id: 33874[/import]

hi, I’m new with corona, but I think I have exactly the same problem as you. Did you find anything about dragging stacked objects ?
JD [import]uid: 52340 topic_id: 9234 reply_id: 37331[/import]