Physics not working well

I’m trying to build a game with some basic platform properties. The problem is that, the physics library is not working well when detecting collisions. Actually, it detects collision after the character has finished it’s movement. If the character is still in the block after he completed his movement, it will be back to its previous position but if it passed the wall, it acts like nothing happened.

A screenshot of how it works now.
This is my create level class:
[lua]module(…, package.seeall )

local sprite = require (“sprite”)
local physics = require (“physics”)
physics.start()
physics.setDrawMode(“hybrid”)

function new()

local tileMaps =
{
{
{ 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 1, },
{ 0, 0, 0, 0, 0, 0, 0, 1, },
{ 0, 0, 0, 0, 0, 0, 0, 1, },
{ 1, 1, 1, 1, 1, 1, 1, 1, },
{ 1, 0, 0, 0, 0, 0, 0, 1, },
{ 1, 1, 1, 1, 1, 1, 1, 1, },
},
{
{ 1, 1, 1, 1, 1, 1, 1, 1, },
{ 2, 0, 0, 0, 0, 0, 0, 3, },
{ 2, 0, 0, 0, 0, 0, 0, 3, },
{ 2, 2, 2, 4, 2, 4, 4, 3, },
{ 2, 4, 4, 4, 0, 0, 0, 3, },
{ 2, 3, 0, 0, 0, 4, 0, 3, },
{ 2, 2, 4, 4, 4, 4, 0, 3, },
{ 2, 3, 0, 0, 0, 0, 0, 3, },
{ 1, 4, 4, 4, 0, 0, 0, 3, },
{ 1, 0, 0, 0, 0, 3, 1, 1, },
{ 1, 3, 3, 3, 3, 3, 1, 1, },
{ 1, 1, 1, 1, 1, 1, 1, 1, },
}
}

– local backGround = display.newImage( “/images/bg1.jpg” )
– backGround.alpha = 0.6

local tileSheet = sprite.newSpriteSheet( “/images/tileSet1.png”,32, 32 )
local tileSet = sprite.newSpriteSet( tileSheet, 1, 4 )

local spriteMap = display.newGroup( )
for y = 0, 11, 1 do
for x = 0, 7, 1 do
local tileSprite = sprite.newSprite( tileSet )
tileSprite.x = x*32+20
tileSprite.y = y*32+20
spriteMap:insert( tileSprite )
end
end

function loadLevel (level)
local i = 1
for y=0,11,1 do
for x=0,7,1 do
– Determine which frame of the tileset to use for this sprite
– As specified by our tilemap
spriteMap[i].currentFrame = tileMaps[level][(1+y)][(1+x)]+1
if spriteMap[i].currentFrame == 2 then
physics.addBody(spriteMap[i],“static”, {friction = 5, density = 0.1})
end
i = i + 1
end
end
end

loadLevel(1)
end[/lua]

This is my create character file:
[lua]module ( …, package.seeall )

local sprite = require(“sprite”)
local physics = require(“physics”)
physics.start( )
–physics.setDrawMode(“debug”)

function new()

local characterSpriteSheet = sprite.newSpriteSheet ( “/images/walk.png”, 30, 31 )
local characterWalkSet = sprite.newSpriteSet ( characterSpriteSheet, 1, 6 )
sprite.add ( characterWalkSet, “walk”, 1, 4, 1000, 0 )

local character = sprite.newSprite(characterWalkSet)
character.x = display.contentCenterX;
character.y = display.contentCenterY;
character:setReferencePoint(display.CenterReferencePoint)
character:prepare(“walk”)
character:play()
physics.addBody(character, {density=0.3, friction=0.6 })

function onScreenTap( event )
if (event.numTaps == 2) then
if (event.x > character.x) then
character.xScale = -1
transition.to ( character, {x = event.x, time=2000} )
else
character.xScale = 1
transition.to ( character, {x = event.x, time=2000} )
end
end
end

Runtime:addEventListener(“tap”, onScreenTap)
end[/lua]
and my main.lua:
[lua]CiderRunMode = {};CiderRunMode.runmode = true;CiderRunMode.assertImage = true;require “CiderDebugger”;

local createCharacter = require ( “scripts.createCharacter” )
local createLevel = require ( “scripts.createLevel” )

display.setStatusBar(display.HiddenStatusBar)
local colePhelps = createCharacter.new()
local myLevel = createLevel.new()[/lua]
How can I correct this? The methods on the physics FAQ page did not help. [import]uid: 154911 topic_id: 29560 reply_id: 329560[/import]

It was probably because of the transition.to() method, I fixed it. [import]uid: 154911 topic_id: 29560 reply_id: 118698[/import]