Physics Help! Ball stuck in corner!

Hello,

I've been building my app, and i have run into a few problems. I have split the screen into two buttons, the left button moves the ball to the left and the right button moves it right, and when both buttons are pressed at the same time it changes the gravity. Now for the problems, I have noticed that when you hold either of the buttons down for 15-20 seconds when the ball is in the corner, the ball freezes and the gravity cannot be changed either. Also, if you hold the ball in the corner for a few seconds you can still move the ball, but you cannot change the gravity. I have searched and tried all of the suggestions that i have found, but none have fixed my problem. I hope I have explained my situation well enough. Any help would be GREATLY appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
_W = display.contentWidth;
_H = display.contentHeight;
 
--Hide Status Bar
display.setStatusBar(display.HiddenStatusBar);
 
system.activate( "multitouch" )
 
local physics = require ("physics");
physics.start();
physics.setGravity(-9.8 , 0);
physics.setDrawMode("debug");
physics.setVelocityIterations( 6 )
 
--Variables
local touchingGround = false;
 
 
--Display Walls----------------------------------------------------------------
local rect_1 = display.newRect(0,0,10,250);
rect_1:setFillColor(255,0,0,255);
rect_1.x = 166;
rect_1.y = 90;
rect_1.rotation = 90;
rect_1.type = "wall1";
physics.addBody(rect_1, "static", {friction = 10, densiy = 1});
        
local rect_2 = display.newRect(0,0,10,348);
rect_2:setFillColor(255,0,0,255);
rect_2.x = 45;
rect_2.y = 259;
rect_2.type = "wall";
physics.addBody(rect_2, "static", {friction = 10, density = 1});
 
local rect_3 = display.newRect(0,0,10,154);
rect_3:setFillColor(255,0,0,255);
rect_3.x = 120;
rect_3.y = 428;
rect_3.rotation = 90;
rect_3.type = "wall1";
physics.addBody(rect_3, "static", {friction = 10, density = 1});
 
local rect_4 = display.newRect(0,0,10,107);
rect_4:setFillColor(255,0,0,255);
rect_4.x = 193;
rect_4.y = 376;
rect_4.type = "wall";
physics.addBody(rect_4, "static", {friction = 10, density = 1});
 
local rect_5 = display.newRect(0,0,10,226);
rect_5:setFillColor(255,0,0,255);
rect_5.x = 285;
rect_5.y = 210;
rect_5.type = "wall";
physics.addBody(rect_5, "static", {friction = 10, density = 1});
        
local rect_6 = display.newRect(0,0,10,102);
rect_6:setFillColor(255,0,0,255);
rect_6.x = 239;
rect_6.y = 319;
rect_6.rotation = 90;
rect_6.type = "wall1";
physics.addBody(rect_6, "static", {friction = 10, density = 1});
---------------------------------------------------------------------------------
 
--Display Ball
local ball = display.newCircle(0, 0, 10);
ball.x = _W * 0.5; ball.y = _H * 0.5;
ball.type = "ball";
physics.addBody( ball, "dynamic", {density = 1, radius = 10, friction = 10, bounce = 0.3, filter = ballFilter});
ball.isAwake = true
ball.isSleepingAllowed = false;
ball.angularDamping = 15;
 
----------------------------------------------------------------------------------
----MultiTouch
local function Button( event )
        local phase = event.phase
        if "began" == phase then
                trigger = true;
                function moveR ()
                        ball:applyForce( 0, -8, ball.x, ball.y)
                end
                        Runtime:addEventListener("enterFrame", moveR)
        if trigger == true and trigger2 == true then
                if(touchingGround == true) then
                        physics.setGravity(-gx, gy);            
                end
        end
        elseif "ended" == phase or "cancelled" == phase then
                trigger = false;
                Runtime:removeEventListener("enterFrame", moveR);
        end
end
 
local function Button2( event )
        local phase = event.phase
        if "began" == phase then
                trigger2 = true;
                function moveL ()
                        ball:applyForce( 0, 8, ball.x, ball.y)
                end
                Runtime:addEventListener("enterFrame", moveL)
        if trigger == true and trigger2 == true then
        if(touchingGround == true) then
                physics.setGravity(-gx, gy);
        end
        end
        elseif "ended" == phase or "cancelled" == phase then
                trigger2 = false;
                Runtime:removeEventListener("enterFrame", moveL);
        end
end
 
button = display.newRect( 0, 0, _W, _H * 0.5 )
button.x = _W * 0.5;
button.y = 120;
button:setFillColor(0, 0, 0, 0)
button:addEventListener( "touch", Button )
 
button2 = display.newRect( 0, 0, _W, _H * 0.5 )
button2.x = _W * 0.5;
button2.y = 360;
button2:setFillColor(0, 0, 0, 0)
button2:addEventListener( "touch", Button2 )
 
----------------------------------------------------------------------------------
--------Update Gravity
function update (event)
                gx, gy = physics.getGravity()
end
 
timer.performWithDelay(10, update, 0);
------------------------------------------------------------------------------------
 
--Collision Filter
function onCollision( event )
        if ( event.phase == "began" ) then
                        if(event.object1.type == "wall" and event.object2.type == "ball") then
                                touchingGround = true;
                        end
                elseif ( event.phase == "ended" ) then
                        touchingGround = false
                end
end
 
Runtime:addEventListener( "collision", onCollision )
------------------------------------------------------------------------------------

I figured it out!

I am experiencing similar issues. What was your solution?

I found my solution here.

views:1723 update:2011/9/26 15:43:22
corona forums © 2003-2011