• How do I check if an entity touches a wall?
    8 replies, posted
I've been trying to check if an entity touches a wall by using this: local trace1 = {ent:GetPos(), ent:GetPos() + Vector(5, 0, 10), ent} local trace2 = {ent:GetPos(), ent:GetPos() + Vector(0, 5, 10), ent} local trace3 = {ent:GetPos(), ent:GetPos() + Vector(-5, 0, 10), ent} local trace4 = {ent:GetPos(), ent:GetPos() + Vector(0, -5, 10), ent} if trace1.Hit or trace2.Hit or trace3.Hit or trace4.Hit then print("Touched Something") end I haven't added in a check if the trace hit is the world but for some reason it doesn't work.
Going off the limited information this might be of some use ENTITY/PhysicsCollide
Doesn't seem to work, I'm trying to make a SWEP that knocks back players and if you knock them back onto a wall they will get stunned. Here's what I've tried: hook.Add("PhysicsCollide", "Stun", function(data, collider) if data.Entity:GetClass() == "worldspawn" then collider:GetEntity():SetMoveType(MOVETYPE_NONE) end end)
Might be hard to track since you'll always be touching the world.. A hacky way might be to see if the players velocity comes to a sudden halt verses gradually. I've not done enough with collision and detection to really give too much advice.
ENTITY/StartTouch Entity/IsWorld function ENT:StartTouch(ent) if ent:IsWorld() then...
You need to start reading the description of stuff on the wiki.
I'll just try what @Rekson suggested, but adding in a boolean if a player recently got hit by the SWEP.
BUMP
ENTITY/PhysicsCollide isn't a global hook, it's called on a sent, if you want to use it you'll have to create your own. Read the wiki page as it also notes that if you aren't using a sent then you can use Entity/AddCallback instead.
Sorry, you need to Log In to post a reply to this thread.