Whats the best way to have an Image onTouch perform an event or function?

I actually have been thinking and was wondering if this approach is to bulky for what it’s worth… Would it be easier for me to just make a touch event anywhere on the screen and make my rocket coordinates follow that? I wouldn’t want it to just go directly to those coordinates but follow them at a set speed. I figured I’d have my phone landscape, x axis starting at left side and have touches accessed from about 0, 200px on the X axis. Anywhere I touch from 0 - 200px X then My rocket would follow that touch + 50px so it will be in front of your finger not under it. Is this about as easy as it sounds? If so would I need a enterFrame Runtime event for the whole screen or how would I go about that. Sorry for all the questions no rush to answer just when you can… I would just be lost without you guys :slight_smile:
EDIT: I have something basic like this for now that just makes the rocket follow the touch. I guess now I need guidance on what to do to make the rocket follow the path in a straight line to the touch or track and follow the touch instead of disappear and reappear at the new coordinates. The drag and follow part works fine.

[lua]function onScreenTouch (event)

if event.x <= 150 then
if rocket.x ~= event.x then
rocket.x = event.x
end

if rocket.y ~= event.y then
rocket.y = event.y
end
end

end
Runtime:addEventListener (“touch”, onScreenTouch)[/lua]
I failed on the transition trying something like this… When i touch the rocket just goes straight to 0,0 and doesn’t move…

[lua]function onScreenTouch (event)

if event.x <= 100 then
if rocket.x ~= event.x then
rocket.x = transition.to(event.x, {time = 500})
end

if rocket.y ~= event.y then
rocket.y = transition.to(event.y, {time = 500})
end
end

end
Runtime:addEventListener (“touch”, onScreenTouch)[/lua] [import]uid: 20272 topic_id: 35441 reply_id: 140891[/import]

Hi @mkjt88,
Since you’re using physics, I’d suggest you track the touch as it moves around the screen, calculating the angle between the rocket and the touch. Then, apply the necessary linear velocity behind the rocket going toward the touch. Don’t use impulses, as each move of the finger will affect the direction of the rocket, and thus you want a “constant” physical movement like linear velocity, not an additive one.

Brent [import]uid: 200026 topic_id: 35441 reply_id: 140999[/import]

Thanks Brent… I understand the logic behind it but I’m not quite so familiar with doing more than very basic maths in programming… Are there any guides, quick tips, or algorithms out there that can get me started on how to do those calculations? [import]uid: 20272 topic_id: 35441 reply_id: 141057[/import]