Modifying the world within the locked callback functions

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
borix134
Prole
Posts: 18
Joined: Sat Aug 10, 2013 5:37 am

Modifying the world within the locked callback functions

Post by borix134 »

So, I would like to call a function that modifies the world within the collision callbacks:

Code: Select all

function land(ship_fixture,planet_fixture)
	ship_fixture:getBody():setAngle(1/(math.cos(ship_fixture:getBody():getX()-planet_fixture:getBody():getX()-planet_fixture:getShape():getRadius())))
end
function beginContact(a, b, coll)  --when the objects initially collide, ship is a
	if a:getUserData()=="ship" then
		a:getBody():setLinearVelocity(0,0)
		land(a,b)
	end
end
function endContact(a, b, coll) --when the objects stop touching
--null
end

function preSolve(a, b, coll) --while the objects are touching
--null
end

function postSolve(a, b, coll, normalimpulse1, tangentimpulse1, normalimpulse2, tangentimpulse2) --dont know what the f*** this is
--null
end
Anywho, I dont really want to use hardon collider, because I am already using physics, and would not want to re-enter all the shapes into the module, as well as risk performance when the callback functions already know when the objects collide. What would be the best way to modify the world whlist triggered by a beginCallback() function?
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Modifying the world within the locked callback functions

Post by Azhukar »

borix134 wrote:What would be the best way to modify the world whlist triggered by a beginCallback() function?
Depends on what you want to modify.

You also have a bug waiting to happen:

Code: Select all

if a:getUserData()=="ship" then
You are not guaranteed that A will be ship, B can be ship while at the same time A is something else. You have to always first determine which of the two fixtures is which.
Post Reply

Who is online

Users browsing this forum: slime and 5 guests