Baloon wont move to down or to the left. HELP!

Hello,

I am making my game and its a helium baloon that changes the law of gravity so it floats up. So im trying to make it so you tap the top of the baloon and it moves down and you tap the left of the baloon and it moves right, and you tap the right of the baloon and it moves to the left.

In my code its supposed to move in all those positions but it only moves to the right when you tap the baloon. Any help.

[code]
–Move the baloon to the right
function reverse(event)
baloon:applyLinearImpulse( 5, 0, baloon.x, baloon.y )
end

function right(event)
baloon:applyLinearImpulse( 0, 5, baloon.x, baloon.y )
end
–End

–Move the baloon up
function moveUp(event)
baloon1:applyLinearImpulse( 0, 15, baloon1.x, baloon1.y )
end

function up(event)
baloon1:applyLinearImpulse( 15, 0, baloon1.x, baloon1.y )
end
–End

–Touch Listeners
baloon:addEventListener(“tap”, reverse)
baloon1:addEventListener(“tap”, moveUp)

[code] [import]uid: 44060 topic_id: 8333 reply_id: 308333[/import]

There is a You-tube video tutorial that does just this:

http://www.youtube.com/watch?v=qEMGcy-mizM

There is a companion video (part 2) that goes along with it. I’m not sure if what you’re trying to do is in the first or 2nd one, but I would watch both of them to get a good grasp of what’s going on.
There are a couple of different things going on.

First you have two objects: baloon and baloon1. You are giving each of them one listener and the function on tap does one thing. “baloon” will only execute the reverse function so it will always apply an impulse to the X. “baloon1” wiil only call “moveUp” at the moment. [import]uid: 19626 topic_id: 8333 reply_id: 29749[/import]

Ok yes i have watched that video before and it doesnt do anything when I add the code do you think that you could help me with that? Thanks [import]uid: 44060 topic_id: 8333 reply_id: 29756[/import]

PLEASE HELP!!! [import]uid: 44060 topic_id: 8333 reply_id: 29920[/import]

Where do you want to tap to determine what direction you want the balloon to move?

In Part 2 of that video there is one event handler to handle the balloon.

function moveBalloon(event)  
 local thisBalloon = event.target -- if you have multiple balloons get the one that was tapped  
 thisBalloon:applyLinearImpulse( 0, 15, event.x, event.y )  
end  

Then for all your balloons:

baloon:addEventListener("tap",moveBalloon)  
baloon1:addEventListener("tap",moveBalloon)  

So there are a couple of very important things going on here. First, we are going to use the same function, “moveBalloon” to move any balloon that’s tapped. So each balloon object (baloon and baloon1) both get event handlers that end up in the same place.

Now once we are inside moveBalloon, we capture which balloon was tapped using the code

 local thisBalloon = event.target  

Now we have a variable called thisBalloon that contains our tapped balloon. Now the video tutorial decided to use where you tapped to determine where the Impulse came from. Your code applies the impulse in the 4 main directions as opposed to the tutorials event code always impulusing up from the touch point.

So I would consider making the change to be more like:

function moveBalloon(event)  
 local thisBalloon = event.target -- if you have multiple balloons get the one that was tapped  
 local dX = thisBalloon.x - event.x  
 local dY = thisBalloon.y - event.y  
 local pushX  
 local pushY  
 if dx \< 0 then -- pushed on left side  
 pushX = 5  
 else   
 pushX = -5  
 end  
 if dy \< 0 then -- pushed on top  
 pushY = 5  
 else  
 pushY = -5 -- tapped on the bottom  
 end   
 thisBalloon:applyLinearImpulse( pushX, pushY, thisBalloon.x, thisBalloon.y )  
end  

Now this is pushing from the center of the balloon and won’t impart spin on them, change the "thisBalloon.x, .y in the applyLinearImpuse to the event.x and event.y variables to put spin on it.

Rob [import]uid: 19626 topic_id: 8333 reply_id: 29930[/import]

PLEASE HELP!!!
dude… figure it out… it ain’t too hard.

take the time to do your own research instead of begging people for help for such simple thing…

when you get stuck on something come back and ask for help but all the resource and code that you can use to start your game programming is out there.

[import]uid: 13978 topic_id: 8333 reply_id: 30091[/import]

stfu aiden u dnt know anything. so u just go to random forums where ur supposed to help ppl but u decide to talk crap bout it. reall mature. btw thank you rob miracle that really helped :slight_smile: [import]uid: 44060 topic_id: 8333 reply_id: 30250[/import]

stfu aiden u dnt know anything. so u just go to random forums where ur supposed to help ppl but u decide to talk crap bout it. reall mature. btw thank you rob miracle that really helped :slight_smile: [import]uid: 44060 topic_id: 8333 reply_id: 30251[/import]

stop whining and learn to program like other people in this forum… and no, the word forum is defined as a public meeting or assembly for open discussion. This forum is not “post your crap code and whine for help” when you can figure a solution after you use your head.

just a thought since you mentioned maturity… hmm… “stfu” ? yeah thats really mature… lol

for the last time, go learn lua like the rest of us and learn to use corona like the rest of us instead of

PLEASE HELP ME!!!

really…

edit: PS - Good luck! =P [import]uid: 13978 topic_id: 8333 reply_id: 30268[/import]

@robmiracle my code isnt working any help

[code]
local physics = require(“physics”)
physics.start()
physics.setGravity(0, -.5)

local sky = display.newImage(“theback.png”)

system.activate( “multitouch” )

local baloon = display.newImage(“yellowbaloon.png”)
baloon.x = 50
baloon.y = 200
physics.addBody(baloon, “dynamic”, {density=5, friction=0, bounce=0 ,radius=20})

local goal = display.newImage(“innerbaloon.png”)
goal.x = 450
goal.y = 270

local metal = display.newImage(“metal.png”)
metal.x = 200
metal.y = 200
physics.addBody(metal, “static”, {density=5, friction=0, bounce=0})

function moveBalloon(event)
local thisBalloon = event.target – if you have multiple balloons get the one that was tapped
thisBalloon:applyLinearImpulse( 0, 15, event.x, event.y )
end

function moveBalloon(event)
local Balloon = event.target – if you have multiple balloons get the one that was tapped
local dX = thisBalloon.x - event.x
local dY = thisBalloon.y - event.y
local pushX
local pushY
if dx < 0 then – pushed on left side
pushX = 5
else
pushX = -5
end
if dy < 0 then – pushed on top
pushY = 5
else
pushY = -5 – tapped on the bottom
end
thisBalloon:applyLinearImpulse( pushX, pushY, Balloon.x, Balloon.y )
baloon:addEventListener(“tap”,moveBalloon)
end
[/code] [import]uid: 44060 topic_id: 8333 reply_id: 30341[/import]

There are a couple of things going on. First, you used the same name for two different functions. You have two called “moveBalloon”. Functions need to have unique names. Corona should catch that and throw an error.

The code in the first moveBalloon function is pretty much as the same in the 2nd one. In either case, your program isn’t calling moveBalloon at all because your event listener is inside the function instead of being in the main chunk.

Try this instead:

function moveBalloon(event)  
 local Balloon = event.target -- if you have multiple balloons get the one that was tapped  
 local dX = thisBalloon.x - event.x  
 local dY = thisBalloon.y - event.y  
 local pushX  
 local pushY  
 if dx \< 0 then -- pushed on left side  
 pushX = 5  
 else   
 pushX = -5  
 end  
 if dy \< 0 then -- pushed on top  
 pushY = 5  
 else  
 pushY = -5 -- tapped on the bottom  
 end   
 thisBalloon:applyLinearImpulse( pushX, pushY, Balloon.x, Balloon.y )  
  
end  
  
baloon:addEventListener("tap",moveBalloon)  

[import]uid: 19626 topic_id: 8333 reply_id: 30361[/import]

Watch your variable naming ie baloon/Balloon/balloon etc
also note that dX is not the same thing as dx

I have amended these things below and moved the addEventListener outside of the moveBalloon function and It now works (with renamed balloon png files)

local physics = require("physics")  
physics.start()   
physics.setGravity(0, -.5)  
   
local sky = display.newImage("theback.png")  
   
system.activate( "multitouch" )  
   
local balloon = display.newImage("yellowballoon.png")  
balloon.x = 50  
balloon.y = 200  
physics.addBody(balloon, "dynamic", {density=5, friction=0, bounce=0 ,radius=20})  
   
local goal = display.newImage("innerballoon.png")  
goal.x = 450  
goal.y = 270  
   
local metal = display.newImage("metal.png")  
metal.x = 200   
metal.y = 200  
physics.addBody(metal, "static", {density=5, friction=0, bounce=0})  
  
function moveBalloon(event)  
 local thisBalloon = event.target -- if you have multiple balloons get the one that was tapped  
 local dx = thisBalloon.x - event.x  
 local dy = thisBalloon.y - event.y  
 local pushX  
 local pushY  
 if dx \< 0 then -- pushed on left side  
 pushX = 5  
 else   
 pushX = -5  
 end  
 if dy \< 0 then -- pushed on top  
 pushY = 5  
 else  
 pushY = -5 -- tapped on the bottom  
 end   
  
 thisBalloon:applyLinearImpulse( pushX, pushY, thisBalloon.x, thisBalloon.y )  
  
end  
  
 balloon:addEventListener("tap", moveBalloon)  

[import]uid: 8366 topic_id: 8333 reply_id: 30363[/import]

the mixed case dX/dx and dY/dy are my fault. Thanks for catching that.

[import]uid: 19626 topic_id: 8333 reply_id: 30369[/import]

Ok well I changed the case but it still doesnt work heres my code:

[code]
local physics = require(“physics”)
physics.start()
physics.setGravity(0, -.5)

local sky = display.newImage(“theback.png”)

system.activate( “multitouch” )

local baloon = display.newImage(“yellowbaloon.png”)
baloon.x = 50
baloon.y = 200
physics.addBody(baloon, “dynamic”, {density=5, friction=0, bounce=0 ,radius=20})

local goal = display.newImage(“innerbaloon.png”)
goal.x = 450
goal.y = 270

local metal = display.newImage(“metal.png”)
metal.x = 200
metal.y = 200
physics.addBody(metal, “static”, {density=5, friction=0, bounce=0})

function moveBalloon(event)
local thisBalloon = event.target – if you have multiple balloons get the one that was tapped
thisBalloon:applyLinearImpulse( 0, 15, event.x, event.y )
end

function moveBalloon(event)
local Balloon = event.target – if you have multiple balloons get the one that was tapped
local dx = thisBalloon.x - event.x
local dy = thisBalloon.y - event.y
local pushx
local pushy
if dx < 0 then – pushed on left side
pushX = 5
else
pushX = -5
end
if dy < 0 then – pushed on top
pushY = 5
else
pushY = -5 – tapped on the bottom
end
thisBalloon:applyLinearImpulse( pushX, pushY, Balloon.x, Balloon.y )
baloon:addEventListener(“tap”,moveBalloon)
end

baloon:addEventListener(“tap”,moveBalloon)
[/code] [import]uid: 44060 topic_id: 8333 reply_id: 30378[/import]

You changed the case of pushx and pushy but in another place you use plusX and plusY.

You also still have two moveBalloon functions. Remove the first one.

Try this:

[code]
local physics = require(“physics”)
physics.start()
physics.setGravity(0, -.5)

local sky = display.newImage(“theback.png”)

system.activate( “multitouch” )

local baloon = display.newImage(“yellowbaloon.png”)
baloon.x = 50
baloon.y = 200
physics.addBody(baloon, “dynamic”, {density=5, friction=0, bounce=0 ,radius=20})

local goal = display.newImage(“innerbaloon.png”)
goal.x = 450
goal.y = 270

local metal = display.newImage(“metal.png”)
metal.x = 200
metal.y = 200
physics.addBody(metal, “static”, {density=5, friction=0, bounce=0})

function moveBalloon(event)
local thisBalloon = event.target – if you have multiple balloons get the one that was tapped
local dx = thisBalloon.x - event.x
local dy = thisBalloon.y - event.y
local pushX
local pushY
if dx < 0 then – pushed on left side
pushX = 5
else
pushX = -5
end
if dy < 0 then – pushed on top
pushY = 5
else
pushY = -5 – tapped on the bottom
end
thisBalloon:applyLinearImpulse( pushX, pushY, thisBalloon.x, thisBalloon.y )
baloon:addEventListener(“tap”,moveBalloon)
end

baloon:addEventListener(“tap”,moveBalloon)
[/code] [import]uid: 19626 topic_id: 8333 reply_id: 30379[/import]

OMG thank you so much and something that both of us dint catch was that in the code there was to event listeners. final code:

[code]
local physics = require(“physics”)
physics.start()
physics.setGravity(0, -.5)

local sky = display.newImage(“theback.png”)

system.activate( “multitouch” )

local baloon = display.newImage(“yellowbaloon.png”)
baloon.x = 50
baloon.y = 200
physics.addBody(baloon, “dynamic”, {density=5, friction=0, bounce=0 ,radius=20})

local goal = display.newImage(“innerbaloon.png”)
goal.x = 450
goal.y = 270

local metal = display.newImage(“metal.png”)
metal.x = 200
metal.y = 200
physics.addBody(metal, “static”, {density=5, friction=0, bounce=0})

function moveBalloon(event)
local thisBalloon = event.target – if you have multiple balloons get the one that was tapped
local dx = thisBalloon.x - event.x
local dy = thisBalloon.y - event.y
local pushX
local pushY
if dx < 0 then – pushed on left side
pushX = -1.5
else
pushX = 1.5
end
if dy < 0 then – pushed on top
pushY = -3
else
pushY = 3 – tapped on the bottom
end
thisBalloon:applyLinearImpulse( pushX, pushY, thisBalloon.x, thisBalloon.y )
end

baloon:addEventListener(“tap”,moveBalloon)
[/code] [import]uid: 44060 topic_id: 8333 reply_id: 30380[/import]