Skip to content
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

Fix trigger_teleport #283

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
- Improved: ep1_citadel_00: Fixed T-pose on vortigaunt and remove leftover chapter messages.
- Fixed: Transitioning doors have sometimes the wrong rotation.
- Fixed: HUD is now hidden when point_viewcontrol takes control.
- Fixed: Triggers not firing outputs when they are disabled and then enabled again while entities are touching it.
- Fixed: Triggers not firing outputs when they are disabled and then enabled again while entities are touching it.
- Fixed: trigger_teleport not working properly with flying NPC's.

0.9.22
- Improved: Weapon selection weights, this should improve selecting the next weapon when current one is empty.
Expand Down
69 changes: 66 additions & 3 deletions entities/entities/trigger_teleport.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,71 @@ if SERVER then
end
end

local function BuildTeleportList(ent, teleportList)
local entry = {
Entity = ent,
Pos = ent:GetPos(),
Ang = ent:GetAngles(),
}
table.insert(teleportList, entry)

local children = ent:GetChildren()
for _, child in pairs(children) do
BuildTeleportList(child, teleportList)
end
end

local function TeleportEntity(sourceEnt, entry, newPos, newAng, newVel)

local teleportEnt = entry.Entity

local solidFlags = teleportEnt:GetSolidFlags()
teleportEnt:SetSolidFlags(FSOLID_NOT_SOLID)

if sourceEnt == teleportEnt then
teleportEnt:SetLocalAngles(newAng)
teleportEnt:SetSaveValue("m_vecAbsVelocity", newVel)
teleportEnt:SetSaveValue("basevelocity", Vector(0,0,0))
-- NOTE: This actually calls CBaseEntity::SetLocalVelocity which is what we want.
teleportEnt:SetAbsVelocity(entry.Pos)
teleportEnt:SetPos(newPos)
else
-- TODO: Re-create this functionality or beg rubat to add it to GMod.
if false then
teleportEnt:CalculcateAbsolutePosition()
end
end

local physObj = teleportEnt:GetPhysicsObject()
if IsValid(physObj) then
physObj:SetVelocity(newVel)

local ang = teleportEnt:GetAngles()
if teleportEnt:IsPlayer() or teleportEnt:GetSolid() == SOLID_BBOX then
ang = Angle(0, 0, 0)
end

physObj:SetPos(teleportEnt:GetPos())
physObj:SetAngles(ang)
end

teleportEnt:SetSolidFlags(solidFlags)
end

local function TeleportObject(ent, newPos, newAng, newVel)
local teleportList = {}
BuildTeleportList(ent, teleportList)

for _, entry in pairs(teleportList) do
TeleportEntity(ent, entry, newPos, newAng, newVel)
end

for _, entry in pairs(teleportList) do
local teleportEnt = entry.Entity
teleportEnt:CollisionRulesChanged()
end
end

function ENT:Touch(ent)
if self:IsDisabled() == true then return end
if self:PassesTriggerFilters(ent) == false then return end
Expand Down Expand Up @@ -74,9 +139,7 @@ if SERVER then
self.CheckpointSet = true
end
else
ent:SetPos(tmp)
ent:SetVelocity(vel)
ent:SetAngles(ang)
TeleportObject(ent, tmp, ang, vel)
end
end
end