Mash up of FollowMe and CollisionDetection

A suggestion for example code - if it was done with the functions in separate files and only the calling of functions and flow control in the main.lua, this might both model realistic design for us newbies and also allow us to successfully use the examples as part of our new programs. IE, copy module like followMe.lua to my own app dir and use the example of how to call the functions from the main.lua of the FollowMe sample code.

My current problem is I am not seeing collisions between my draggable objects since I modulized and mashed together the FollowMe and CollisionDetection samples:

http://codelock.com/corona/DragCollide.zip

My desire is to have the crates static on the right side of the screen.

The draggable text objects get dragged over to touch one of the 2 crates.

When a text object touches a crate object, I was going to make an action that the text object slides into the crate disappearing off the screen. Like it gets sucked in. Nothing fancy needed. This is just a person with their finger choosing “I am going to put this text into this crate”

Anyway my problem is that I no longer can cause any collision signals?

Thanks for any tips. I think this would be useful sample code for others once working since dragging with collision seems like a common need. I have seen another user asking for hints to create the common “drag object to other object where first object then disappears” which reminds me of drag to trash can functionality. [import]uid: 10016 topic_id: 3087 reply_id: 303087[/import]

Great suggestion for structuring our sample code and encouraging a good workflow/approach.

See the SampleCode/MultiPucks project for an example of combining dragging with physics. The project folder contains an external library called gameUI.lua that you’ll need. The basic usage is like this:

local gameUI = require ("gameUI") -- gameUI.lua in project folder  
  
local function dragBody( event )  
 gameUI.dragBody( event )   
 -- Substitute one of these lines for the line above to see what happens!  
 -- gameUI.dragBody( event, { maxForce=400, frequency=5, dampingRatio=0.2 } ) -- slow, elastic dragging  
 -- gameUI.dragBody( event, { maxForce=20000, frequency=10, dampingRatio=0.2, center=true } ) -- very tight dragging, snaps to object center  
  
-- assume pre-existing physics bodies "circle1" and "circle2"  
  
circle1:addEventListener("touch", dragBody)  
circle2:addEventListener("touch", dragBody)  
  

See how this goes for you. And you’re right that this is a common programming task that we need to document better. I’ll take that action item. :slight_smile:

Tim
[import]uid: 8196 topic_id: 3087 reply_id: 9063[/import]

I got it working by taking from your suggested Multi-Puck but had to also add the collision detection functions also as a module. Also the objects to be dragged had to not be “static”… in FollowMe you can drag static objects.

All ok… but when I collide the text with the stationary crate and use a transition to disappear it off the screen… to a pixel x distance that is off the screen… I see in the Terminal window that the event keeps firing probably forever.

I tried to have it remove after the collision with the crate is over, but that makes the object disappear too fast, instantly it seems instead of with the nice 1.5 second transition fly away and fade.

http://codelock.com/corona/DragCollide2.zip

Another question I have is about the center pivoting of the object. In my case I’m dragging a piece of text and just want it to stay horizontally oriented and then slide out off the screen without spinning or angling or tipping etc. I’ve tried turning center on and off so far as the global settings for the gameUI.dragBody… but so far the text item turns 90 degrees when tweening out off the screen which I don’t understand unless it is just the center point seeking the transition destination.

Thanks,

  • April [import]uid: 10016 topic_id: 3087 reply_id: 9110[/import]

Hey thanks for asking this query, as I require the same functionality of drag, collide and removeSelf() on collision. Please help me. Read through the post and the multi puck example. But, I don’t know how I can use it and achieve what I need. Also in my cae the objects are static. [import]uid: 44499 topic_id: 3087 reply_id: 37681[/import]

Can anyone please tell me how to remove the colliding objects after the drag collide. [import]uid: 44499 topic_id: 3087 reply_id: 37683[/import]