Change position on Collision began

Hello 
Is is possible to change physic element during colision ??
I have code like this:

local function onLocalCollision( self, event )          if ( event.phase == "began" ) then                  if(event.other.name == "ball") then             print ("GOOOOOOOL")                                       teamLocal[1].player.x = 200             teamLocal[1].player.y = 200             p1ScoreText.text = "1";                        end         --print( self.name .. ": collision began with " .. tostring(event.other.name) )              elseif ( event.phase == "ended" ) then         print( self.name .. ": collision ended with " .. tostring(event.other.name) )     end end

p1ScoreText.text = “1”; - is working

teamLocal[1].player.x = 200 - it is not working

teamLocal[1].player.y = 200 - it is not working

this is physics for player:

     

physics.addBody(value.player, "dynamic", { density=1, friction=0.8, bounce=0.2, radius=25 })             value.player.isFixedRotation=true             value.player.linearDamping = 4   

and this is my player

   paddle = display.newImageRect(resourceFile, 80, 80)     paddle.x = xcoordinate     paddle.y = ycoordinate     paddle.name = name

Greeting Thank You

Ok, I got it 
I need to do it with timer.

timer.performWithDelay(100, listener)

where in listener is replacement od pawns.

But my ball is still in movement after reseting positions : D

and physics stop doesnt work…

Hi, when you move the object it is still owned by the physics engine so when it is re-positioned it  still has the previous actions working on it.

I would set the objects LinearVelocity to 0 after moving it : i.e. setLinearVelocity(0,0)

https://docs.coronalabs.com/api/type/Body/setLinearVelocity.html

Maybe also set its body to False .i.e object.isBodyActive = false then re-enable it after the movement, otherwise it may collide/ interact with other bodies causing weird results.

Cheers

I will try, thank you for help :slight_smile:

You may also want to reset the angularVelocity with body:setAngularVelocity(0).

Ok, I got it 
I need to do it with timer.

timer.performWithDelay(100, listener)

where in listener is replacement od pawns.

But my ball is still in movement after reseting positions : D

and physics stop doesnt work…

Hi, when you move the object it is still owned by the physics engine so when it is re-positioned it  still has the previous actions working on it.

I would set the objects LinearVelocity to 0 after moving it : i.e. setLinearVelocity(0,0)

https://docs.coronalabs.com/api/type/Body/setLinearVelocity.html

Maybe also set its body to False .i.e object.isBodyActive = false then re-enable it after the movement, otherwise it may collide/ interact with other bodies causing weird results.

Cheers

I will try, thank you for help :slight_smile:

You may also want to reset the angularVelocity with body:setAngularVelocity(0).