Wherever you touch, the object goes Help Needed!

Like the title says, how do I get a object to go to the spot wherever the user touches? Thanks in advance. [import]uid: 54001 topic_id: 11313 reply_id: 311313[/import]

Play around with horacebury’s code in this thread:

http://developer.anscamobile.com/forum/2011/05/04/windmills-and-pendulums

In particular this part:

local tap = function( event )  
 local ball = display.newCircle( event.x, event.y, 20 )  
 physics.addBody( ball, "dynamic", { friction=1, bounce=.1, density=1, radius=20 } )  
 function ball:timer( event )  
 if (ball.y \> 1500) then  
 timer.cancel( ball.t )  
 ball.t = nil  
 ball:removeSelf()  
 end  
 end  
 ball.t = timer.performWithDelay( 10000, ball, 3 )  
end  

You tap a spot and a ball with physics is drawn [import]uid: 31262 topic_id: 11313 reply_id: 41062[/import]

I think he wants an existing object to go where the user touches the screen.

How are you moving the object now? If you’re using setLinearVelocity(), my code in this thread may help. Instead of following another object, though, follow the touch.

http://developer.anscamobile.com/forum/2010/10/31/how-make-object-follow-another-object [import]uid: 58455 topic_id: 11313 reply_id: 41064[/import]

I still don’t know what to do. I have not applied any movement functions that I’m willing to use on my object yet.

I just want the user to touch anywhere on the screen and the current object on the screen will go there in an instant with no transitioning. Speed of light.

It’s like teleporting by touch. It’s that simple.

Also, if any of you guys know how to keep an object on another object without moving then please let me know.

Like how do I keep the yoke of an egg on the white part of the egg. (2 physics objects need to stay together) [import]uid: 54001 topic_id: 11313 reply_id: 41068[/import]

Oh, well then just set the x and y of the object to the touch event’s x and y.

For the yolk and egg thing, you might want to read up on physics joints. [import]uid: 58455 topic_id: 11313 reply_id: 41074[/import]

I tried the x y thing and it did not work. What do I do now? [import]uid: 54001 topic_id: 11313 reply_id: 41082[/import]

Post your code or we can’t help. [import]uid: 58455 topic_id: 11313 reply_id: 41084[/import]

It’s not about posting code, I just want to know how to do it.

Just explain in an example. Wherever the user touches the object on the screen goes instantly. NO transitioning. [import]uid: 54001 topic_id: 11313 reply_id: 41123[/import]

Is this a joke? That’s like 10 lines of code…if you aren’t willing to put that much effort into learning, how do you expect to make an entire game? [import]uid: 58455 topic_id: 11313 reply_id: 41124[/import]

You say “That’s like 10 lines of code” … well easier said then done Sherlock.

I tried multiple ways already but nothing happens the way I want. Apparently you don’t fully understand I guess.

*EDIT: Edited by me (Peach) because we don’t accept this kind of personal attack. Please keep name calling and insults for your own website and read the forum rules. [import]uid: 54001 topic_id: 11313 reply_id: 41131[/import]

@supercyclone77 - Little more give and take, please.

Code assuming your object is called “ball” and your background is called "background;
[lua]function moveball (event)
ball.x = event.x
ball.y = event.y
end
background:addEventListener(“tap”,moveball)[/lua]

Peach [import]uid: 52491 topic_id: 11313 reply_id: 41132[/import]