Last active
March 14, 2022 22:23
-
-
Save adamnejm/31c9f05d5d48bcbc02c40e5b48253a90 to your computer and use it in GitHub Desktop.
GLua - Remove Entity on Floor Contact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if SERVER then | |
local function spawn_ent(pos) | |
local ent = ents.Create("prop_physics") | |
ent:SetModel("models/hunter/blocks/cube05x05x05.mdl") | |
ent:SetPos(pos) | |
ent:Spawn() | |
-- Make use of the `PhysicsCollide` callback to know when entity collides | |
ent:AddCallback("PhysicsCollide", function(self, data) | |
-- Check if the colliding entity is the world (`Entity(0)`) and how steep the surface is | |
-- The lower the number, the flatter the surface must be to consider it a 'floor' | |
if data.HitEntity == Entity(0) and data.HitNormal.z < -0.6 then | |
self:Remove() | |
end | |
end) | |
end | |
-- If we press E, spawn a prop 200 units above the ground relative to where we're looking | |
hook.Add("KeyPress", "", function(ply, bind) | |
if ply ~= Entity(1) or bind ~= IN_USE then return end | |
spawn_ent(ply:GetEyeTrace().HitPos + Vector(0, 0, 200)) | |
end) | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment