Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

"Object overlaps when dragging object fast
Started by avinashkhubchandani101 Jun 19 2019 11:58 PM

No replies to this topic
collision collisions drag dragging
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

avinashkhubchandani101

[GLOBAL: userInfoPane.html]
avinashkhubchandani101
  • Observer

  • 3 posts
  • Corona SDK

display.setStatusBar(display.HiddenStatusBar)

system.activate("multitouch")

local topY = display.screenOriginY --Numerical value for the top of the screen
local rightX = display.contentWidth - display.screenOriginX --Numerical value for the right of the screen
local bottomY = display.contentHeight - display.screenOriginY --Numerical value for the bottom of the screen
local leftX = display.screenOriginX --Numerical value for the left of the screen
local screenW = rightX - leftX --Numerical value for the width of the screen
local screenH = bottomY - topY --Numerical value for the height of the screen

local direction = 1
local speed = .2

leftWall = display.newRect(leftX + screenW/40,display.contentCenterY,screenW/20,display.contentHeight)
rightWall = display.newRect(rightX - screenW/40, display.contentCenterY,screenW/20,display.contentHeight)
middleLine = display.newRect(screenW/2,screenH/2,display.contentWidth,3)

player1 = display.newRect(screenW/2 + leftX, topY + screenH/10 , screenW/5 , screenH/25)

ball = display.newCircle(leftX + screenW/2, topY + screenH/2, screenW/30)

function oneTouch(event)
    player1 = event.target
    local phase = event.phase

    if phase == "began" then 
        display.getCurrentStage():setFocus(event.target,event.id)
        player1.markX = player1.x
    	player1.markY = player1.y

    elseif ("moved" == phase and event.y < display.contentHeight/2) then
    	player1.x = player1.markX - (event.x - event.xStart)
        player1.y = player1.markY - (event.y - event.yStart)
        
        if player1.y > display.contentHeight/2 then
        	player1.y = display.contentHeight/2 - player1.height/2
        end

    elseif (phase == "ended" or phase == "cancelled") then
           display.getCurrentStage():setFocus (player1,nil)

    end

    return true
end

player1:addEventListener("touch",oneTouch)

function moveBall()
	if direction == 1 then
		ball.x = ball.x + speed
		ball.y = ball.y - speed
	elseif direction == 2 then
		ball.x = ball.x - speed
		ball.y = ball.y - speed
	elseif direction == 3 then
		ball.x = ball.x - speed
		ball.y = ball.y + speed
	elseif direction == 4 then
		ball.x = ball.x + speed
		ball.y = ball.y + speed
	end
end

Runtime:addEventListener( "enterFrame", moveBall )

local function checkCollision()
    if ball.x - 15 < leftWall.x + 5 then
		if direction == 3 then
			direction = 4
		elseif direction == 2 then
			direction = 1
		end
    elseif ball.x + 15 > rightWall.x - 5 then
		if direction == 1 then
			direction = 2
		elseif direction == 4 then
			direction = 3
		end
	end
   
   if (inside(ball,player1) ) then
		speed = speed + .1
		if direction == 1 then
			direction = 4
		elseif direction == 2 then
			direction = 3
		end 
    
    end
end

Runtime:addEventListener( "enterFrame", checkCollision )

function inside(obj1, obj2)
        return obj1.contentBounds.xMin < obj2.contentBounds.xMax
                and obj1.contentBounds.xMax > obj2.contentBounds.xMin
                and obj1.contentBounds.yMin < obj2.contentBounds.yMax
                and obj1.contentBounds.yMax > obj2.contentBounds.yMin
end

 

When i drag my paddle towards the ball fast it just overlaps the ball does not make collision but it works pretty OK when I drag paddle slowly.. I used zoomEven scale





[topic_controls]
[/topic_controls]

Also tagged with one or more of these keywords: collision, collisions, drag, dragging