Ball rotation?

If you want to rotate a physics object use the code I posted here:

http://forums.coronalabs.com/topic/39690-rotate-a-physics-object/?p=206113

In my app there is a ball when i schoot it, the ball begans to rotate, but when the ball falls back to the ground, the rotation ends immediately and the ball continues to move  without rotation!!

What can i do to avoid that the ball’s rotation ends before that the ball is stopped??

Post your code.

  module(..., package.seeall)         local W = display.contentWidth   local H = display.contentHeight    function new() local localGroup = display.newGroup()     local localGroup = display.newGroup()   local pausa = display.newImage("pausa.png") pausa.x = 600 pausa.y = 40   local bglivelli = display.newImage("grass.jpg") bglivelli.x = W/2 bglivelli.y = H/2     local levelText = display.newText("level 1", 45, 1200, "Arial", 50)     local ground1 = display.newImage("linea.jpg") ground1.x = W/2 ground1.y = 1100 physics.addBody(ground1,"static",{})   local circle = display.newImage("palla.png", 80, 80) circle.x = 367 circle.y = 870      physics.addBody(circle,"dinamic", {density = 1.0, friction = 0.3, bounce = 0.2, radius = 35})     local ground2 = display.newRect(0, 1280, 720, 1) physics.addBody(ground2, "static", {})     local roof1 = display.newRect(0, 0, 180, 0.5) physics.addBody(roof1, "static", {})    local roof2 = display.newRect(540, 0, 180, 0.5) physics.addBody(roof2, "static", {})            local wallS = display.newRect(0,0,0.5, 1280) physics.addBody(wallS, "static", {})   local wallD = display.newRect(720, 0, 1, 1280) physics.addBody(wallD, "static", {})   local bar1 = display.newImage("bar.png") bar1.x = 180 bar1.y = 50 physics.addBody(bar1, "static", {})   local bar2 = display.newImage("bar.png") bar2.x = 540 bar2.y = 50 physics.addBody(bar2, "static", {})   local reloadB = display.newImage("reloadB.png") reloadB.x = 120 reloadB.y = 40 reloadB.scene = "level1"     local sX = bar1.x local sY = bar1.y   local eX = bar2.x local eY = bar2.y            localGroup:insert(roof1)  localGroup:insert(roof2)  localGroup:insert(bglivelli)  localGroup:insert(ground1)  localGroup:insert(levelText)  localGroup:insert(circle)  localGroup:insert(ground2)  localGroup:insert(wallS)  localGroup:insert(wallD)  localGroup:insert(bar1)  localGroup:insert(bar2)  localGroup:insert(reloadB)  localGroup:insert(pausa)      function changeScene(e) if e.phase == "ended" then director:changeScene(e.target.scene) end end    local physics=require ("physics") local isPaused = false   function pausePhysics( event )     if "began" == event.phase then         if isPaused == false then             physics.pause()             isPaused = true                                       local mainB = display.newImage("button1.png")             mainB.x = W/2             mainB.y = H/2             mainB.scene = "menu"             mainB:addEventListener("touch", changeScene)                          local mainBText = display.newText("Main Menu", 0, 0, "Arial", 50)             mainBText.x = mainB.x             mainBText.y = mainB.y                          local levelSelB = display.newImage("button1.png")             levelSelB.x = mainB.x              levelSelB.y = mainB.y - 150             levelSelB.scene = "levelSel"             levelSelB:addEventListener("touch", changeScene)                          local levelSelBText = display.newText ("Level Select", 0, 0, "Arial", 40)             levelSelBText.x = levelSelB.x             levelSelBText.y = levelSelB.y                          local resumeB = display.newImage("button1.png")             resumeB.x = mainB.x              resumeB.y = mainB.y + 150                          local resumeBText = display.newText("Continue", 0, 0, "Arial", 50)             resumeBText.x = resumeB.x             resumeBText.y = resumeB.y                          function resume(e) if "began" == event.phase then if isPaused == true then  physics.start()  isPaused = false    --remove buttons  mainB:removeSelf()  mainBText:removeSelf()  levelSelB:removeSelf()  levelSelBText:removeSelf()  resumeB:removeSelf()  resumeBText:removeSelf()  end  end  end  resumeB:addEventListener("touch", resume)                                                                                                                    -- elseif isPaused == true then            -- physics.start()             --isPaused = false          end     end end       pausa:addEventListener( "touch", pausePhysics )   physics.start()    function circleTouch(event) if event.phase == "began" then display.getCurrentStage():setFocus(circle)   else if  event.phase == "ended" then   circle:removeEventListener("touch", circleTouch)   circle:applyLinearImpulse(event.xStart - event.x, event.yStart - event.y, circle.x, circle.y) display.getCurrentStage():setFocus(nil)   function rotateCircle()     circle.rotation = 0     transition.to( circle, { time=5000, rotation=360, onComplete=rotateRect } ) end rotateCircle()       end end end     circle:addEventListener("touch", circleTouch)                 local function checkForHit(object, from\_x, from\_y, to\_x, to\_y)  local hits = physics.rayCast( from\_x, from\_y, to\_x, to\_y )  if hits[1].object == circle then print ("You Win") local text = display.newImage( "button1.png") text.x = W/2 text.y = H/2 localGroup:insert(text) text.scene= "level1" text:addEventListener("touch", changeScene)   local textT = display.newText("Next Level", 0, 0, "Arial", 45) textT.x = text.x textT.y = text.y     end end         Runtime:addEventListener( "enterFrame", function() checkForHit(circle, sX, sY, eX, eY )end  )   reloadB:addEventListener("touch", changeScene)             return localGroup   end    

I can’t run that code because it isn’t complete - you’ve not posted enough code for me to run.

The first rule of debugging is Boil your code down to just the problem code. That way, you can work on the part which is a problem without interfering with other code and, if you need to, you can post it for other people to debug.

Reduce your code to just the piece which is the problem, then post it.

If I understand your description properly, the ball (with enough friction) would stop spinning when it hits another object, but would bounce off somewhere else. It all depends on your specific body setup.

And what can i do to solve the problem?

Well, I did just tell you to reduce the code down to the only code which has the problem. Until then, I can’t help you!