Transition.to Multiple object selection to go to multiple targets

Here’s the deal and I am hoping and praying someone can help me out with some simple logic.

  1. I have 5 guys/girls :slight_smile: on the left
  2. I have 5 kittens on the right.

This is what I am trying to do:

If I touch guy/girl 1 and then I touch kitten 3… I want the guy/girl to go to that kitten (3). The same holds true for the rest. It requires two touches to get players moving to the kittens they are paired up with.

The last thing is after they make contact/collide it plays a sound…

Any help guys really please and thank you [import]uid: 53149 topic_id: 10709 reply_id: 310709[/import]

Here you go…
[lua]require “physics”

physics.start()
physics.setGravity(0,0)
local rand = math.random

local selectedActor = nil
local function distanceBetween( point1, point2 )

local xfactor = point2.x-point1.x ; local yfactor = point2.y-point1.y
local distanceBetween = math.sqrt((xfactor*xfactor) + (yfactor*yfactor))
return distanceBetween
end

for a = 1 , 5 do
local actor = display.newRect(10, a*75, 50,50)
–actor:setFillColor(rand(255),rand(255),rand(255))
actor:setFillColor(0,0,200)

function actor:tap(e)
if selectedActor ~= nil then
selectedActor:setFillColor(0,0,200)
selectedActor = self
else
selectedActor = self
end
selectedActor:setFillColor(0,200,200)

end

function actor:collision(e)
self:setLinearVelocity(0,0)
— code to play sound or do something else goes here
self:removeEventListener(“tap”,self)
self:removeEventListener(“collision”,self)

end

physics.addBody(actor,“dynamic”,{ bounce=0, friction = 0, filter = { categoryBits = 1, maskBits = 2}})

actor:addEventListener(“tap”,actor)
actor:addEventListener(“collision”,actor)
end
for a = 1 , 5 do
local kitten = display.newRect(250, a*75, 50,50)
–box:setFillColor(rand(255),rand(255),rand(255))
kitten:setFillColor(0,200,0)

function kitten:tap(e)
if selectedActor ~= nil then
–get velocity vector direction
local vX = (self.x - selectedActor.x )/distanceBetween(self,selectedActor)
local vY = (self.y - selectedActor.y )/distanceBetween(self,selectedActor)

–set velocity
selectedActor:setLinearVelocity(vX*100,vY*100)

selectedActor:setFillColor(200,0,200)
selectedActor = nil
end
end

physics.addBody(kitten,“static”,{ bounce=0, friction = 0, filter = { categoryBits = 2, maskBits = 1}})

kitten:addEventListener(“tap”,kitten)
end[/lua] [import]uid: 48521 topic_id: 10709 reply_id: 38911[/import]

@chinmay.patil Thank you so much! This is a great start to what I am trying to do. Excellent! [import]uid: 53149 topic_id: 10709 reply_id: 39051[/import]