How do I pull my finger down my phone screen and release to make a ball shoot up and bounce of walls and blocks ? The shorter I pull down the shorter distance the ball goes .
‘touch’ Listener + vector math + linear impulse + physics bodies (ball and walls)
This may have some of the code you need, but it isn’t exactly what you asked for :
https://forums.coronalabs.com/topic/47218-bullets/#entry243948
This too might be useful, having the drag part I believe: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/01/PredictingTrajectory.zip
Yeah that’s kind of what I want to do but can I do it without the predictions part ? I want the ball to be at the bottom of the screen and when the user pull their finger down the screen the ball launches
Yes, you sure can.
I am merely pointing you in the right direction and giving you some code to look at.
You should be able extract the bits you need from that, or at least get pointed in the right direction.
The essence of what you want to do is:
-
In touch ‘began’ - Track <x0, y0> of touch.
-
(optionally) in touch ‘moved’ using <x0,y0> and current <x,y> draw a line. (you’ll want to delete any prior line you made first)
You optionally draw a line each move to represent the vector.
- In touch ‘ended’ - Delete any (optional) line; Then Using <x0,y0> and current event <x,y> calculate a vector and then calculate:
- Impulse vector as vector * some value you will have to determine works best for you.
Then apply that as a linear impulse to the ball.
Easy Peasy.
Again, the two examples should have these kinds of calculations in them.
‘touch’ Listener + vector math + linear impulse + physics bodies (ball and walls)
This may have some of the code you need, but it isn’t exactly what you asked for :
https://forums.coronalabs.com/topic/47218-bullets/#entry243948
This too might be useful, having the drag part I believe: https://github.com/roaminggamer/RG_FreeStuff/raw/master/AskEd/2017/01/PredictingTrajectory.zip
Yeah that’s kind of what I want to do but can I do it without the predictions part ? I want the ball to be at the bottom of the screen and when the user pull their finger down the screen the ball launches
Yes, you sure can.
I am merely pointing you in the right direction and giving you some code to look at.
You should be able extract the bits you need from that, or at least get pointed in the right direction.
The essence of what you want to do is:
-
In touch ‘began’ - Track <x0, y0> of touch.
-
(optionally) in touch ‘moved’ using <x0,y0> and current <x,y> draw a line. (you’ll want to delete any prior line you made first)
You optionally draw a line each move to represent the vector.
- In touch ‘ended’ - Delete any (optional) line; Then Using <x0,y0> and current event <x,y> calculate a vector and then calculate:
- Impulse vector as vector * some value you will have to determine works best for you.
Then apply that as a linear impulse to the ball.
Easy Peasy.
Again, the two examples should have these kinds of calculations in them.