Try this:
main.lua:
[lua]-- tail demo
local physics = require(“physics”)
physics.start()
local a = display.newCircle( 100, 300, 25 )
physics.addBody( a, “dynamic” )
a:applyForce( 5, -8 )
local b = display.newCircle( -100, -100, 10 )
b:setFillColor( 0,255,0 )
local list, dofollow = {}, false
function enterFrame(event)
– record the A object’s location
list[#list+1] = {x=a.x,y=a.y}
– once there is 15 or more frames of location data then we can start following
if (#list >= 15) then
– switch on following
dofollow = true
end
– only bother following when there is a decent distance between the two objects - in this case it is 15 frames worth of data
if (dofollow) then
local t = list[1]
b.x, b.y = t.x, t.y
table.remove( list, 1 )
end
end
Runtime:addEventListener( “enterFrame”, enterFrame )[/lua]
[import]uid: 8271 topic_id: 26357 reply_id: 107002[/import]