physics question?

Hi All,

I have a small question about physics  :slight_smile:

My First code is below:

[lua]local physics = require( “physics” )
physics.start()
motiony=0

local ball = display.newCircle( 50, 50, 20 )
ball:setReferencePoint(display.TopCenterReferencePoint)
physics.addBody( ball, “dynamic”, { friction=0, bounce=0 } )
ball.x = 100; ball.y = 100;

local wall = display.newRect( 0, 0, 20, 65 )
wall:setReferencePoint(display.TopCenterReferencePoint)
wall.x = 100; wall.y = 200
physics.addBody( wall, “static”, { friction=0, bounce=0 } )[/lua]

This code working properly.

Ball is dropping and it is stopping on wall… This is good.

And my seconde code is below too  :slight_smile:

[lua]local physics = require( “physics” )
physics.start()
motiony=0

local ball = display.newCircle( 50, 50, 20 )
ball:setReferencePoint(display.TopCenterReferencePoint)
physics.addBody( ball, “static”, { friction=0, bounce=0 } )
ball.x = 100; ball.y = 100;

local wall = display.newRect( 0, 0, 20, 65 )
wall:setReferencePoint(display.TopCenterReferencePoint)
wall.x = 100; wall.y = 200
physics.addBody( wall, “static”, { friction=0, bounce=0 } )

local up =display.newRect( 0, 0, 65, 65 )
up.x= 200
up.y= 400

function up:touch()
motiony = 2
end
up:addEventListener(“touch”,up)

local function moveball()
ball.y=ball.y + motiony
end

local function stop (event)
if event.phase ==“ended” then
motiony = 0
end
end
Runtime:addEventListener(“enterFrame”, moveball)
Runtime:addEventListener(“touch”, stop )
[/lua]

What am i want?

i want my ball when it comes to wall stop. Yes i know, i am changing x position but there is a wall. My Ball should stop :slight_smile:

is it possible or not?

Hello @gurcanhamali,

When physics collisions are concerned, at least one of the two bodies (or both) must be “dynamic” type (the default). Static + static will not generate a collision, as you are doing in this example.

Best regards,

Brent

Thank you brent

I changed my BodyType to dynamic and i set [lua]physics.setGravity( 0, 0 )[/lua] and it seems the my problem is solved  :slight_smile:

Hello @gurcanhamali,

When physics collisions are concerned, at least one of the two bodies (or both) must be “dynamic” type (the default). Static + static will not generate a collision, as you are doing in this example.

Best regards,

Brent

Thank you brent

I changed my BodyType to dynamic and i set [lua]physics.setGravity( 0, 0 )[/lua] and it seems the my problem is solved  :slight_smile: