Here is a quick sample of a following object orbiting a parent object using math.rad(), math.sin() and math.cos():
local distance = 100 local parentObj = display.newRect(display.contentWidth \* 0.5, display.contentHeight \* 0.5, 50, 50) local followingObj = display.newRect(0, 0, 25, 25) local function update() parentObj.rotation = parentObj.rotation + 1 if parentObj.rotation \> 360 then parentObj.rotation = 0 elseif parentObj.rotation \< 0 then parentObj.rotation = 360 end local radians = math.rad(parentObj.rotation) followingObj.x, followingObj.y = parentObj.x + (math.sin(radians) \* distance), parentObj.y - (math.cos(radians) \* distance) end Runtime:addEventListener( "enterFrame", update )
The important part is the last 2 lines of the update function,where it gets the current angle of the parent object, converts that to radians and then sets the position of the following object relative to the parentObj’s position based on that angle:
local radians = math.rad(parentObj.rotation) followingObj.x, followingObj.y = parentObj.x + (math.sin(radians) \* distance), parentObj.y - (math.cos(radians) \* distance)
The distance is hardcoded to 100 in my example, but presumably you would want to use distance = ship.height * 0.5 or something like that so that it always appears at the bottom of the ship.
And obviously you’ll need to change it to set the initial position of new smoke trail objects, rather than updating an existing object’s position.