I'm trying to handle collisions between the player and spikes, and when the player collides with the spikes, reset the player position. Here's my code for handling the collision, using callbacks:
Code: Select all
function beginContact(a, b, coll)
if a:getUserData() == "Player" and b:getUserData() == "Spikes" then
player.body:setPosition(player.x, player.y)
end
end
I know the collision works fine normally, before I tried to reset the player's position, I printed a line to the console and everything worked fine. It's the "setPosition()" function that's somehow giving me an error. Here's the zip file with the code (I'm still trying to figure out how to make a .love file, sorry). Thanks for any help!Error
main.lua:225: Box2D assertion failed: m_world->IsLocked() == false
Traceback
[C]: in function 'setPosition'
main.lua:225: in function <main.lua:223>
[C]: in function 'update'
main.lua:161: in function 'update'
[C]: in function 'xpcall'