hook.Add("OnEntityCreated", "TTT_Collide", function(ent)
if ent:IsRagdoll() or (ent:IsWeapon() and string.StartWith("weapon_ttt_", ent:GetClass())) then
timer.Simple(0, function()
if IsValid(ent) then
ent:SetCustomCollisionCheck(true)
end
end)
end
end)
hook.Add("ShouldCollide", "TTT_Collide", function(ent1, ent2)
if !IsValid(ent1) or !IsValid(ent2) then return end
if ent1:IsRagdoll() and ent2:IsRagdoll() then
if ent1.GetCollisionGroup and ent1:GetCollisionGroup() == COLLISION_GROUP_WEAPON and ent2.GetCollisionGroup and ent2:GetCollisionGroup() == COLLISION_GROUP_WEAPON then
return false
end
end
if ent1:IsWeapon() and ent2:IsWeapon() or ent1:IsWeapon() and ent2:IsRagdoll() or ent2:IsWeapon() and ent1:Ragdoll() then
if ent1.GetCollisionGroup and ent1:GetCollisionGroup() == COLLISION_GROUP_WEAPON and ent2.GetCollisionGroup and ent2:GetCollisionGroup() == COLLISION_GROUP_WEAPON then
return false
end
end
end)
this code breaks my physics for some reason, when it shouldn't.
Anyone got any hint for me, why it happens?
Could you post the code on another site? Facepunch code tags are currently broken.
I see
hastebin
When you call "SetCustomCollisionCheck", also try calling Entity/CollisionRulesChanged
Entity/CollisionRulesChanged just tells gmod to re evaluate the collisions, i suspect there's some kind of error occuring
can you check the server console and see if there's a lua error?
How did I miss this?
This was a mistake of an beginner.
I got embarrassed. You now may take all my titles and land.
Which ferrari will you buy now, the red one? Can't remember which one willox had
pick yourself up and get right back in there
Wow, it is still breaking physics after a short period of time.
It doesn't error or something, it just breaks my physics for some reason.
Is there any way I can prevent this?
I need to use the hook in order to not make the weapons collide with dead players making them fly
around the map.
hmmm how about this?
hook.Add("OnEntityCreated","TTT_Collide",function(ent)
timer.Simple(0.1,function()
if ent and ent:IsValid() and ent:IsRagdoll() then--make sure the ent is a ragdoll
ent:SetCollisionGroup(COLLISION_GROUP_WORLD)--will collide with nothing except the world and static stuff
end
end)
end)
It would fall through props.
It only breaks physics when used improperly - I didn't read the thread, but whatever your code is, make sure to treat every should collide case. For example if you want to disable collisions between entity class A and entity class B, then, for example, you'd need to do TWO if statements: if ent1 is class A and if ent2 is class B then return false, and additionally if ent1 is class B and if ent2 is class A then return false.
Make sure to always call for collision rules changed after updating them etc, and you should be fine
It breaks as soon as I try to use it with weapons.
It's running on TTT, so only TTT could mess up things for me, but I can't find anything in the code of TTT doing this potentially.
ShouldCollide will break physics if the two results don't match generally. I really think it should fail noisly and revert to some fallback because it will completely cripple a physics thread till the scrds instance is restarted.
check the server console, are there any lua errors?
if there's an error inside a hook, the hook functions that come after will not happen
There is no error, for 100%
how about this?
hook.Add("OnEntityCreated", "TTT_Collide", function(ent)
timer.Simple(1, function()
if IsValid(ent) then
if ent:IsRagdoll() or ent:IsWeapon() then
ent:SetCustomCollisionCheck(true)
ent:CollisionRulesChanged()
end
end)
end
end)
hook.Add("ShouldCollide", "TTT_Collide", function(ent1, ent2)
if !IsValid(ent1) or !IsValid(ent2) then return end--is either entity invalid?
if !ent1:IsRagdoll() and !ent1:IsWeapon() then return end--is ent1 not a candidate?
if !ent2:IsRagdoll() and !ent2:IsWeapon() then return end--is ent2 not a candidate?
return false--if we made it here, then a ragdoll/weapon is colliding with a ragdoll/weapon
end)
Sorry, you need to Log In to post a reply to this thread.