Object moves faster than expected

I’m working on a side scrolling game and having so problems with the objects. So far, I have 3 objects. Object and Object2 move fine across the screen at a decent speed. But object3 moves at lightening speed. I don’t know why, I’m pretty sure it has the same coding as the first two? And if I add an Object4, that too will move across the screen at 100mph. I am very confused. Can anyone help?

[code]
function objectSpawn()
object = display.newImage(“object.png”)
object.x = 510
object.y = math.random(0,280)
localGroup:insert(object)
transition.to (object, {time=3500, x=-50})
physics.addBody(object, {bounce=0.6})
object.angularVelocity = math.random(-200,200)
object.myName = “object”
object.collision = onobjectCollision
object:addEventListener(“collision”, object)
end

function onobjectCollision ( self,event )
if ( event.phase == “began” ) then
if ( self.myName == “object” ) then
if ( event.other.myName == “player” ) then
playBad()
score.setScore( score.getScore() + 25 )
self:removeSelf()
elseif (event.other.myName == “leftwall”) then
self:removeSelf()
elseif (event.other.myName == “rightwall”) then
self:removeSelf()
end
end
end
end
timer1 = timer.performWithDelay(1600, objectSpawn, 0 )

function object2Spawn()
object2 = display.newImage(“object2.png”)
object2.x = 510
object2.y = math.random(0,280)
localGroup:insert(object2)
transition.to (object2, {time=3500, x=-50})
physics.addBody(object2, {bounce=0.6})
object2.angularVelocity = math.random(-200,200)
object2.myName = “object2”
object2.collision = onobject2Collision
object2:addEventListener(“collision”, object2)
end

function onobject2Collision ( self,event )
if ( event.phase == “began” ) then
if ( self.myName == “object2” ) then
if ( event.other.myName == “player” ) then
playBad()
score.setScore( score.getScore() + 25 )
self:removeSelf()
elseif (event.other.myName == “leftwall”) then
self:removeSelf()
elseif (event.other.myName == “rightwall”) then
self:removeSelf()
end
end
end
end
timer1 = timer.performWithDelay(1800, object2Spawn, 0 )

function object3Spawn()
object3 = display.newImage(“object3.png”)
object3.x = 510
object3.y = math.random(0,280)
localGroup:insert(object3)
transition.to (object3, {time=3500, x=-50})
physics.addBody(object3, {bounce=0.6})
object3.angularVelocity = math.random(-200,200)
object3.myName = “object3”
object3.collision = onobject3Collision
object3:addEventListener(“collision”, object3)
end

function onobject3Collision ( self,event )
if ( event.phase == “began” ) then
if ( self.myName == “object3” ) then
if ( event.other.myName == “player” ) then
playBad()
score.setScore( score.getScore() + 25 )
self:removeSelf()
elseif (event.other.myName == “leftwall”) then
self:removeSelf()
elseif (event.other.myName == “rightwall”) then
self:removeSelf()
end
end
end
end
timer1 = timer.performWithDelay(2000, object3Spawn, 0 ) [import]uid: 114389 topic_id: 26296 reply_id: 326296[/import]

The code below is what I’ve got working from your posted code. I had to put circles in place of the images and declare the localGroup display group. Let me know if I got it right, because I’m not seeing any odd object speeds…

main.lua:
[lua]local physics = require(“physics”)
physics.start()
physics.setGravity(0,0)
physics.setDrawMode(“hybrid”)

local localGroup = display.newGroup()

function objectSpawn()
object = display.newCircle(0,0,50) – Image(“object.png”)
object:setFillColor(255,0,0)
object.x = 510
object.y = math.random(0,280)
localGroup:insert(object)
transition.to (object, {time=3500, x=-50})
physics.addBody(object, {bounce=0.6})
object.angularVelocity = math.random(-200,200)
object.myName = “object”
object.collision = onobjectCollision
object:addEventListener(“collision”, object)
end

function onobjectCollision ( self,event )
if ( event.phase == “began” ) then
if ( self.myName == “object” ) then
if ( event.other.myName == “player” ) then
playBad()
score.setScore( score.getScore() + 25 )
self:removeSelf()
elseif (event.other.myName == “leftwall”) then
self:removeSelf()
elseif (event.other.myName == “rightwall”) then
self:removeSelf()
end
end
end
end
timer1 = timer.performWithDelay(1600, objectSpawn, 0 )

function object2Spawn()
object2 = display.newCircle(0,0,50) – newImage(“object2.png”)
object2:setFillColor(0,255,0)
object2.x = 510
object2.y = math.random(0,280)
localGroup:insert(object2)
transition.to (object2, {time=3500, x=-50})
physics.addBody(object2, {bounce=0.6})
object2.angularVelocity = math.random(-200,200)
object2.myName = “object2”
object2.collision = onobject2Collision
object2:addEventListener(“collision”, object2)
end

function onobject2Collision ( self,event )
if ( event.phase == “began” ) then
if ( self.myName == “object2” ) then
if ( event.other.myName == “player” ) then
playBad()
score.setScore( score.getScore() + 25 )
self:removeSelf()
elseif (event.other.myName == “leftwall”) then
self:removeSelf()
elseif (event.other.myName == “rightwall”) then
self:removeSelf()
end
end
end
end
timer1 = timer.performWithDelay(1800, object2Spawn, 0 )

function object3Spawn()
object3 = display.newCircle(0,0,50) – newImage(“object3.png”)
object3:setFillColor(0,0,255)
object3.x = 510
object3.y = math.random(0,280)
localGroup:insert(object3)
transition.to (object3, {time=3500, x=-50})
physics.addBody(object3, {bounce=0.6})
object3.angularVelocity = math.random(-200,200)
object3.myName = “object3”
object3.collision = onobject3Collision
object3:addEventListener(“collision”, object3)
end

function onobject3Collision( self, event )
if ( event.phase == “began” ) then
if ( self.myName == “object3” ) then
if ( event.other.myName == “player” ) then
playBad()
score.setScore( score.getScore() + 25 )
self:removeSelf()
elseif (event.other.myName == “leftwall”) then
self:removeSelf()
elseif (event.other.myName == “rightwall”) then
self:removeSelf()
end
end
end
end
timer1 = timer.performWithDelay(2000, object3Spawn, 0 )[/lua]
[import]uid: 8271 topic_id: 26296 reply_id: 106749[/import]

Hey. I also can’t see anything which would make the speed of object 3 different from the others. Are you setting velocity/other forces etc elsewhere? [import]uid: 67933 topic_id: 26296 reply_id: 106757[/import]

Hmm that’s interesting. Before I read the responses, I re-wrote it and it still went too fast. But yes horacebury, I used your code and it now works. Thanks a ton! Though it still leaves me stumped why it responded the way it did. But thanks again! [import]uid: 114389 topic_id: 26296 reply_id: 106934[/import]

It can only have been something else in your code - I would take a look at the parts you didn’t post. But not for too long unless it happens again. I suspect the reason is fairly simple but tricky to identify without seeing it before. [import]uid: 8271 topic_id: 26296 reply_id: 106973[/import]