Making character move to where mouse was clicked

Hi I’ve been looking for example code on how-to achieve this but I can’t find anything does anyone know where I can find examples of this? [import]uid: 167310 topic_id: 32812 reply_id: 332812[/import]

You have to use a Runtime listener for touch events and in the handler for that, move your character to the x,y for the event. Or you can have an invisible button covering the touch area to do the same thing.

local function movePlayer(x,y)  
 -- code to move the player goes here  
end  
  
local function handleTouch(event)  
 if event.phase == "ended" then  
 movePlayer(event.x,event.y)  
 end  
 return true  
end  
  
Runtime:addEventListener("touch", handleTouch)  

[import]uid: 19626 topic_id: 32812 reply_id: 130454[/import]

OK thanks I’ll implement this in my code and see how I get no… [import]uid: 167310 topic_id: 32812 reply_id: 130460[/import]

You have to use a Runtime listener for touch events and in the handler for that, move your character to the x,y for the event. Or you can have an invisible button covering the touch area to do the same thing.

local function movePlayer(x,y)  
 -- code to move the player goes here  
end  
  
local function handleTouch(event)  
 if event.phase == "ended" then  
 movePlayer(event.x,event.y)  
 end  
 return true  
end  
  
Runtime:addEventListener("touch", handleTouch)  

[import]uid: 19626 topic_id: 32812 reply_id: 130454[/import]

OK thanks I’ll implement this in my code and see how I get no… [import]uid: 167310 topic_id: 32812 reply_id: 130460[/import]