I am trying to make the collision of my player with a certain object change to the game over screen.
It visually transitions fine, but I get an error message when it changes to the game over screen and the entire game over screen works fine, and the button to return to the mainmenu even makes the sound that its supposed to when clicked, but it does not change the scene.
In the terminal it says:
Runtime error
…/minigame1.lua:144: attempt to call method ‘getLinearVelocity’ (a nil value)
stack traceback:
[C]: in function ‘getLinearVelocity’
…/minigame1.lua:137>
?: in function <?:214>
This is my code:
[lua]local function onCollision(self, event )
if ( event.phase == “began” ) then
if event.other.IsGround then
player.canJump = true
end
if event.other.IsDeadly then
director:changeScene( “gameover” )
end
if event.other.IsGoal then
director:changeScene( “winner” )
end
elseif ( event.phase == “ended” ) then
if event.other.IsGround then
player.canJump = false
end
end
end
player.collision = onCollision
player:addEventListener( “collision”, player )
local onUpdate = function(event)
if player.state == STATE_WALKING then
player:applyForce(player.direction * 10, 0, player.x, player.y)
elseif player.state == STATE_IDLE then
local vx, vy = player:getLinearVelocity()
if vx ~= 0 then
player:setLinearVelocity(vx * 0.9, vy)
end
end
end
Runtime:addEventListener(“enterFrame”, onUpdate)
[lua]I have been stumped by this problem for over two weeks, how do I fix this? [import]uid: 37067 topic_id: 6747 reply_id: 306747[/import]