Traversing display objects while object is using a diagonal movement. Is it possible? - Question

Like the title states, I was just wondering if it would be possible. Right now I am using transition.to statements using the x and y axis to give my display objects some movement animations. But then I realized when I made a transition.to stating the objects need to move from off the screen, onto the screen, then off the screen again, it messed up the movements I was going for completely and the display objects would go all over the place on screen because of there being two transition.to statements using x coordinates. I was wondering if there was another way to traverse objects. I can’t use groups because the physics won’t follow the objects when in a group. Is there any other way? I am trying to make a diagonal obstacle, and how I am doing it forces me to use the x and y axis with a transition.to statement.

I have spine so I can animate the display objects through that. Although that doesn’t help the fact that the obstacle is supposed to be diagonal.

Thanks for reading everyone.

local function tryThis() op4.x = W/2 - 500 op4.y = H/2 - 400 op4.isVisible = true op4.isBodyActive = true op4.type = "obstacle" op6.x = W/2 - 100 op6.y = H/2 op6.isVisible = true op6.isBodyActive = true op6.type = "obstacle" op11.x = W/2 + 120 op11.y = H/2 - 130 op11.isVisible = true op11.isBodyActive = true op11.type = "obstacle" op9.x = W/2 + 300 op9.y = H/2 + 300 op9.isVisible = true op9.isBodyActive = true op9.type = "obstacle" op3.x = W/2 + 600 op3.y = H/2 - 500 op3.isVisible = true op3.isBodyActive = true op3.type = "obstacle" -- op6 - When object touches another object, it reflects back and forth between others local function collision() if op6.y == H/2 - 140 then -- When op6 collides with another object, those objects react local function equalize() local function normalize() local function normRotation() transition.to(op6, {time = 400, rotation = op6.rotation - 8}) transition.to(op4, {time = 350, rotation = op4.rotation - 10}) end transition.to(op6, {time = 400, rotation = op6.rotation + 8}) transition.to(op4, {time = 350, rotation = op4.rotation + 10, onComplete = normRotation}) transition.to(op4, {time = 350, y = H/2 - 400, x = W/2 - 500}) end transition.to(op6, {time = 400, rotation = op6.rotation - 8}) transition.to(op4, {time = 350, rotation = op4.rotation - 10}) transition.to(op4, {time = 350, y = H/2 - 390, x = W/2 - 490, onComplete = normalize}) end transition.to(op4, {time = 350, rotation = op4.rotation + 10}) transition.to(op4, {time = 350, y = H/2 - 440, x = W/2 - 520, onComplete = equalize}) transition.to(op6, {time = 400, rotation = op6.rotation + 8}) transition.to(op6, {time = 1630, y = H/2 + 220, x = W/2 + 200, onComplete = collision}) end if op6.y == H/2 + 220 then local function equalize() local function normalize() local function normRotation() transition.to(op6, {time = 400, rotation = op6.rotation + 8}) transition.to(op9, {time = 350, rotation = op9.rotation - 10}) end transition.to(op6, {time = 400, rotation = op6.rotation - 8}) transition.to(op9, {time = 400, rotation = op9.rotation + 10, onComplete = normRotation}) transition.to(op9, {time = 350, y = H/2 + 300, x = W/2 + 300}) end transition.to(op6, {time = 400, rotation = op6.rotation + 8}) transition.to(op9, {time = 350, rotation = op9.rotation - 10}) transition.to(op9, {time = 350, y = H/2 + 290, x = W/2 + 290, onComplete = normalize}) end transition.to(op9, {time = 350, rotation = op9.rotation + 10}) transition.to(op9, {time = 350, y = H/2 + 340, x = W/2 + 320, onComplete = equalize}) transition.to(op6, {time = 400, rotation = op6.rotation - 8}) transition.to(op6, {time = 1630, y = H/2 - 140, x = W/2 - 380, onComplete = collision}) end end -- op11 - When object touches another object, it reflects back and forth between others local function collision2() if op11.y == H/2 - 370 then -- Continues moving op11, when it collides with another object they react local function equalize() local function normalize() local function normRotation() transition.to(op3, {time = 350, rotation = op11.rotation + 8}) transition.to(op3, {time = 350, y = H/2 - 500, x = W/2 + 600}) end transition.to(op3, {time = 350, y = H/2 - 510, x = W/2 + 610}) transition.to(op3, {time = 350, rotation = op11.rotation - 8, onComplete = normRotation}) end transition.to(op3, {time = 350, rotation = op11.rotation + 8}) transition.to(op3, {time = 300, y = H/2 - 480, x = W/2 + 590}) transition.to(op11, {time = 350, rotation = op11.rotation - 8, onComplete = normalize}) end transition.to(op3, {time = 350, rotation = op3.rotation - 8}) transition.to(op3, {time = 300, y = H/2 - 530, x = W/2 + 620}) transition.to(op11, {time = 350, rotation = op11.rotation + 8, onComplete = equalize}) transition.to(op11, {time = 800, y = H/2 - 120, x = W/2 + 90, onComplete = collision2}) end if op11.y == H/2 - 120 then local function equalize() transition.to(op11, {time = 350, rotation = op11.rotation + 8}) end transition.to(op11, {time = 350, rotation = op11.rotation - 8, onComplete = equalize}) transition.to(op11, {time = 800, y = H/2 - 370, x = W/2 + 430, onComplete = collision2}) end end -- Moves display object in a diagonal direction to form an obstacle transition.to(op11, {time = 1900, y = H/2 - 370, x = W/2 + 420, onComplete = collision2}) transition.to(op6, {time = 1900, y = H/2 - 140, x = W/2 - 360, onComplete = collision}) -- This is the traversing code from off screen, onto screen, then off again transition.to(op4, {time = 9000, x = W/2 - 2700, tag = "transTag"}) transition.to(op6, {time = 9000, x = W/2 - 2300, tag = "transTag"}) transition.to(op9, {time = 9000, x = W/2 - 1800, tag = "transTag"}) transition.to(op11, {time = 9000, x = W/2 - 2000, tag = "transTag"}) end tryThis()

Here is the code I am working with. I should have posted this up, sorry.

local function tryThis() op4.x = W/2 - 500 op4.y = H/2 - 400 op4.isVisible = true op4.isBodyActive = true op4.type = "obstacle" op6.x = W/2 - 100 op6.y = H/2 op6.isVisible = true op6.isBodyActive = true op6.type = "obstacle" op11.x = W/2 + 120 op11.y = H/2 - 130 op11.isVisible = true op11.isBodyActive = true op11.type = "obstacle" op9.x = W/2 + 300 op9.y = H/2 + 300 op9.isVisible = true op9.isBodyActive = true op9.type = "obstacle" op3.x = W/2 + 600 op3.y = H/2 - 500 op3.isVisible = true op3.isBodyActive = true op3.type = "obstacle" -- op6 - When object touches another object, it reflects back and forth between others local function collision() if op6.y == H/2 - 140 then -- When op6 collides with another object, those objects react local function equalize() local function normalize() local function normRotation() transition.to(op6, {time = 400, rotation = op6.rotation - 8}) transition.to(op4, {time = 350, rotation = op4.rotation - 10}) end transition.to(op6, {time = 400, rotation = op6.rotation + 8}) transition.to(op4, {time = 350, rotation = op4.rotation + 10, onComplete = normRotation}) transition.to(op4, {time = 350, y = H/2 - 400, x = W/2 - 500}) end transition.to(op6, {time = 400, rotation = op6.rotation - 8}) transition.to(op4, {time = 350, rotation = op4.rotation - 10}) transition.to(op4, {time = 350, y = H/2 - 390, x = W/2 - 490, onComplete = normalize}) end transition.to(op4, {time = 350, rotation = op4.rotation + 10}) transition.to(op4, {time = 350, y = H/2 - 440, x = W/2 - 520, onComplete = equalize}) transition.to(op6, {time = 400, rotation = op6.rotation + 8}) transition.to(op6, {time = 1630, y = H/2 + 220, x = W/2 + 200, onComplete = collision}) end if op6.y == H/2 + 220 then local function equalize() local function normalize() local function normRotation() transition.to(op6, {time = 400, rotation = op6.rotation + 8}) transition.to(op9, {time = 350, rotation = op9.rotation - 10}) end transition.to(op6, {time = 400, rotation = op6.rotation - 8}) transition.to(op9, {time = 400, rotation = op9.rotation + 10, onComplete = normRotation}) transition.to(op9, {time = 350, y = H/2 + 300, x = W/2 + 300}) end transition.to(op6, {time = 400, rotation = op6.rotation + 8}) transition.to(op9, {time = 350, rotation = op9.rotation - 10}) transition.to(op9, {time = 350, y = H/2 + 290, x = W/2 + 290, onComplete = normalize}) end transition.to(op9, {time = 350, rotation = op9.rotation + 10}) transition.to(op9, {time = 350, y = H/2 + 340, x = W/2 + 320, onComplete = equalize}) transition.to(op6, {time = 400, rotation = op6.rotation - 8}) transition.to(op6, {time = 1630, y = H/2 - 140, x = W/2 - 380, onComplete = collision}) end end -- op11 - When object touches another object, it reflects back and forth between others local function collision2() if op11.y == H/2 - 370 then -- Continues moving op11, when it collides with another object they react local function equalize() local function normalize() local function normRotation() transition.to(op3, {time = 350, rotation = op11.rotation + 8}) transition.to(op3, {time = 350, y = H/2 - 500, x = W/2 + 600}) end transition.to(op3, {time = 350, y = H/2 - 510, x = W/2 + 610}) transition.to(op3, {time = 350, rotation = op11.rotation - 8, onComplete = normRotation}) end transition.to(op3, {time = 350, rotation = op11.rotation + 8}) transition.to(op3, {time = 300, y = H/2 - 480, x = W/2 + 590}) transition.to(op11, {time = 350, rotation = op11.rotation - 8, onComplete = normalize}) end transition.to(op3, {time = 350, rotation = op3.rotation - 8}) transition.to(op3, {time = 300, y = H/2 - 530, x = W/2 + 620}) transition.to(op11, {time = 350, rotation = op11.rotation + 8, onComplete = equalize}) transition.to(op11, {time = 800, y = H/2 - 120, x = W/2 + 90, onComplete = collision2}) end if op11.y == H/2 - 120 then local function equalize() transition.to(op11, {time = 350, rotation = op11.rotation + 8}) end transition.to(op11, {time = 350, rotation = op11.rotation - 8, onComplete = equalize}) transition.to(op11, {time = 800, y = H/2 - 370, x = W/2 + 430, onComplete = collision2}) end end -- Moves display object in a diagonal direction to form an obstacle transition.to(op11, {time = 1900, y = H/2 - 370, x = W/2 + 420, onComplete = collision2}) transition.to(op6, {time = 1900, y = H/2 - 140, x = W/2 - 360, onComplete = collision}) -- This is the traversing code from off screen, onto screen, then off again transition.to(op4, {time = 9000, x = W/2 - 2700, tag = "transTag"}) transition.to(op6, {time = 9000, x = W/2 - 2300, tag = "transTag"}) transition.to(op9, {time = 9000, x = W/2 - 1800, tag = "transTag"}) transition.to(op11, {time = 9000, x = W/2 - 2000, tag = "transTag"}) end tryThis()

Here is the code I am working with. I should have posted this up, sorry.