ball sliding little after collision

hey guys

my ball slides after collision of an object…

code of collision:

obj1 = event.object1

obj2 = event.object2

elseif (obj1.name == “key” and obj2.name == “ball”) then

           if obj1 ~= nil then 

             print(“key collision”)

             display.remove(obj1)

             obj1 = nil 

             user.keys = user.keys + 1 

             loadsave.saveTable(user,“user.json”)

           end  

elseif (obj1.name == “ball” and obj2.name == “key”) then

           if obj2 ~= nil then 

             display.remove(obj2)

             obj2 = nil 

             user.keys = user.keys + 1     

             loadsave.saveTable(user,“user.json”)

end

not posted entire collision code

Is it set to event.phase ended?

began phase 

Anyone please??

Please post enough code to repoduce problem

This code creates my keys

 function scoreUp() -- body score = score + 100 user.score2 = score scoreText.text = "Score:"..score scoreText.anchorX = 1 scoreText.x = screenRight - scoreText.width \* 0.2 loadsave.saveTable(user,"user.json") if user.score2 \>= 20000 then local keyRand = math.random(1,200) if keyRand \> 198 then print("key rand is ';".. keyRand) keyCounter = keyCounter + 1 keys[keyCounter] = display.newImageRect( sceneGroup, "menuImages/ruby.png",40,60) keys[keyCounter].x = math.random(screenLeft + 80 , screenRight - 80) keys[keyCounter].y = screenTop - keys[keyCounter].height keys[keyCounter].name = "key" physics.addBody(keys[keyCounter],"dynamic") keys[keyCounter].isFixedRotation = true trans\_key = transition.to (keys[keyCounter],{y = screenBottom + keys[keyCounter].height , time = math.random(1200,1500)}) end end end

this code is of ball

-- check which ball to display if user.isRedEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/red-white-ball.png",75,75) elseif user.isYellowEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/yellow-white-ball.png",75,75) elseif user.isPurpleEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/purple-white-ball.png",75,75) elseif user.isOrangeEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/orange-white-ball.png",75,75) elseif user.isBlueEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/blue-white-ball.png",75,75) elseif user.isGreenEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/green-white-ball.png",75,75) end ball.x = centerX ball.y = centerY ball.name = "ball" physics.addBody(ball,"dynamic",{radius = ballRadius, bounce = 0.4,filter = {category = 1, maskBits = 1 }}) ball.isFixedRotation = true

when ball collides with key, keys are removed but ball starts sliding

Collision is above which i posted earlier

Try using this:

character:setLinearVelocity(0, nil)

and place it when you collision occurs, for example,

local function onCollision(event) character:setLinearVelocity(0, nil) elseif (obj1.name == "key" and obj2.name == "ball") --etc... end

 

That didnt worked…i tried that earlier

set one or both of the objects to a sensor to prevent collision response between them

Thanks dave but i figured out this issue !

But making an object sensor will prevent all the collisions happening to it… i want my ball to collide with key so there is no sense in making them sensor

Sensors detect collisions. Sensors do not move as the result of the collision. In the sci-fi shooter I’m building now, I had to make both the player’s ship and enemy ships sensors because if they end up spawning close to another object that would move to weird angles. My bullets are not sensors (ships don’t crash into each other in this game, just bullets) and it’s working like a champ.

Rob

Can you provide the link to all your games in google play ??

Is it set to event.phase ended?

began phase 

Anyone please??

Please post enough code to repoduce problem

This code creates my keys

 function scoreUp() -- body score = score + 100 user.score2 = score scoreText.text = "Score:"..score scoreText.anchorX = 1 scoreText.x = screenRight - scoreText.width \* 0.2 loadsave.saveTable(user,"user.json") if user.score2 \>= 20000 then local keyRand = math.random(1,200) if keyRand \> 198 then print("key rand is ';".. keyRand) keyCounter = keyCounter + 1 keys[keyCounter] = display.newImageRect( sceneGroup, "menuImages/ruby.png",40,60) keys[keyCounter].x = math.random(screenLeft + 80 , screenRight - 80) keys[keyCounter].y = screenTop - keys[keyCounter].height keys[keyCounter].name = "key" physics.addBody(keys[keyCounter],"dynamic") keys[keyCounter].isFixedRotation = true trans\_key = transition.to (keys[keyCounter],{y = screenBottom + keys[keyCounter].height , time = math.random(1200,1500)}) end end end

this code is of ball

-- check which ball to display if user.isRedEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/red-white-ball.png",75,75) elseif user.isYellowEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/yellow-white-ball.png",75,75) elseif user.isPurpleEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/purple-white-ball.png",75,75) elseif user.isOrangeEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/orange-white-ball.png",75,75) elseif user.isBlueEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/blue-white-ball.png",75,75) elseif user.isGreenEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/green-white-ball.png",75,75) end ball.x = centerX ball.y = centerY ball.name = "ball" physics.addBody(ball,"dynamic",{radius = ballRadius, bounce = 0.4,filter = {category = 1, maskBits = 1 }}) ball.isFixedRotation = true

when ball collides with key, keys are removed but ball starts sliding

Collision is above which i posted earlier

Try using this:

character:setLinearVelocity(0, nil)

and place it when you collision occurs, for example,

local function onCollision(event) character:setLinearVelocity(0, nil) elseif (obj1.name == "key" and obj2.name == "ball") --etc... end

 

That didnt worked…i tried that earlier

set one or both of the objects to a sensor to prevent collision response between them