Hi guys,
I have code in witch you can hit the ball with a swipe and it works nice when you swipe on a straight line and with a good speed, otherwise it’s not work nice at all. If you hit it on a curved line it goes not on the desire direction, if you hit it slow it will go slow, you can even stop the ball.
Desirable result is simple to hit the ball and have it going on expected direction. And have the speed of the hit ball of a speed of swipe with a set minimum speed to prevent it from going to slow if it’s possible, otherwise just a constant speed. What is the ways to make it work nicely?
[lua]
local physics = require(“physics”)
physics.start()
local ball = display.newCircle(150, 10, 30)
physics.addBody(ball)
ball.gravityScale = 0
local function swipe(event)
local phase=event.phase
if phase == “began” then
elseif phase == “moved” then
local eventXMove = (event.xStart - event.x)*-6
local eventYMove = (event.yStart - event.y)*-6
ball:setLinearVelocity(eventXMove, eventYMove)
transition.cancel()
elseif phase == “cancelled” or phase == “ended” then
end
return true
end
ball:addEventListener(“touch”, swipe)
transition.to(ball, {time=3000, x=40, y=400})[/lua]