As my first Corona project, I’m working on a simple “castle defense” game, where the castle flings boulders at monsters using a catapult. Thanks to the “angry birds” sample code in the docs, I’ve gotten my head around the basic physics, i.e. applyForce. But I can’t figure out a formula that gets the boulder to land reliably at the screen location that’s touched.
I’m keeping the vertical (upward) launch force static at -15, and setting the horizontal force proportional to how far I want it to travel.
Here’s the relevant code (paraphrased):
vForce = -15
hForce = (touchEvent.x - launchOrigin.x) / (display.contentWidth - launchOrigin.x) \* 25
-- 25 is an arbitrary number figured out via trial and error, based on the vertical force and mass.
-- It gets the boulder to land exactly on the touch location at one specific location, but if I
-- touch 100 pixels to the right, the boulder will land about 20 pixels to the side of where
-- I touched
boulder.applyForce(hForce, vForce, boulder.x, boulder.y)
Am I wrong to assume that twice the horizontal force (with all other things constant) should make the boulder travel exactly twice the distance? [import]uid: 42158 topic_id: 19832 reply_id: 319832[/import]