-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow multiple collision listeners per entity, for all instances, regardless of old ent:PhysicsCollide() #1868
Allow multiple collision listeners per entity, for all instances, regardless of old ent:PhysicsCollide() #1868
Conversation
@thegrb93 I've left a TODO note commenting on I know that using SetVelocity on players can result in no change and creating entities can result in collisions regardless of group, if either are done from inside the collision listener, but is there a crash exploit or some other critical issue the delay fixes? Or is it to guarantee a 1-tick delay so that players don't encounter and fix those aforementioned odd behaviors themselves? |
This needs to be coalesced into a class. The current implementation is way too fragmented and messy. |
Should also co-author @proton0va |
I have time to class-ify it right now, so I can do that. |
It's working now. Mind testing it out? |
|
Using these to test: --@name 1
--@author
--@server
--prop.setPropClean( false )
local ent = prop.create( chip():getPos() + Vector( 0, 0, 50 ), Angle(), "models/hunter/blocks/cube025x025x025.mdl", false )
ent:setColor( Color( 255, 0, 0, 255 ) )
ent:addCollisionListener( function()
print( "1 listener a" )
end, "a" )
ent:addCollisionListener( function()
print( "1 listener b" )
end, "b" )
ent:addCollisionListener( function()
print( "1 listener ?1" )
end )
ent:addCollisionListener( function()
print( "1 listener ?2" )
end )
timer.simple( 1.5, function()
print( "1 removed b" )
ent:removeCollisionListener( "b" )
ent:getPhysicsObject():setVelocity( Vector( 0, 0, 100 ) )
timer.simple( 1.5, function()
print( "1 removed all" )
ent:removeCollisionListener()
ent:getPhysicsObject():setVelocity( Vector( 0, 0, 100 ) )
timer.simple( 1.5, function()
print( "1 added a" )
ent:addCollisionListener( function()
print( "1 listener a" )
end, "a" )
ent:getPhysicsObject():setVelocity( Vector( 0, 0, 100 ) )
end )
end )
end ) --@name 2
--@author
--@server
local ent = find.byModel( "models/hunter/blocks/cube025x025x025.mdl" )[1]
ent:setColor( Color( 0, 255, 0, 255 ) )
ent:addCollisionListener( function()
print( "2 listener a" )
end, "a" )
ent:addCollisionListener( function()
print( "2 listener b" )
end, "b" )
ent:addCollisionListener( function()
print( "2 listener ?1" )
end )
ent:addCollisionListener( function()
print( "2 listener ?2" )
end )
timer.simple( 1.5, function()
print( "2 removed b" )
ent:removeCollisionListener( "b" )
ent:getPhysicsObject():setVelocity( Vector( 0, 0, 100 ) )
timer.simple( 1.5, function()
print( "2 removed all" )
ent:removeCollisionListener()
ent:getPhysicsObject():setVelocity( Vector( 0, 0, 100 ) )
timer.simple( 1.5, function()
print( "2 added a" )
ent:addCollisionListener( function()
print( "2 listener a" )
end, "a" )
ent:getPhysicsObject():setVelocity( Vector( 0, 0, 100 ) )
end )
end )
end ) |
Did you 'git pull'? The exists function was added in sflib.lua |
Yes, I did. You never defined |
Never mind, the copy in my addons folder was out of date across the other files. |
Everything seems to be working except for |
Also, adding an unnmaed listener will incorrectly override existing unnamed listeners, instead of adding to the list. |
I changed the behavior so that calling without a name argument uses '""' instead adding/removing an array of listeners. This behavior is easier to manage. |
Ah. Alright then. |
…ardless of old ent:PhysicsCollide() (#1868) * Allow for multiple collision listeners --------- Co-authored-by: thegrb93 <[email protected]> Co-authored-by: UnusualOtter <[email protected]> de11335
Similar to #1865, but allows entities that already have
:PhysicsCollide()
from glua to still have starfall collision listeners. Also allows for different chip instances to have their own listeners on the same entity.Bonus side effect due to how
addCollisions()
was reworked: previously, if two entities had collision listeners, any time either of them made a collision, it would call both listeners, resulting in callbacks being called for the collisions of entities they weren't associated with. This issue is now resolved with the rewrite.