Make the gizmo update its position when out of bounds (#60)

* Make the gizmo update it's position when out of bounds
+ Gizmos can be selected when we set their collision bounds to be within the world.
This commit is contained in:
vlazed 2024-12-19 10:41:28 -06:00 committed by GitHub
parent eefbda5c3b
commit e05843450e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -11,8 +11,28 @@ local VECTOR_FRONT = RGM_Constants.VECTOR_FRONT
local ANGLE_DISC = Angle(0, 90, 0)
local ANGLE_ARROW_OFFSET = Angle(0, 90, 90)
-- How much we should try to contain the player and the gizmo
local DISTANCE_PADDING = 2
-- How much player's velocity should influence collision bound
local PLAYER_WEIGHT = 0.9
-- How much gizmo's own velocity should influence collision bound
local GIZMO_WEIGHT = 0.1
function ENT:Think()
local pl = self.Owner
local size = self.DefaultMinMax
-- Extend the collision bounds to include us, with some velocity tracking to ensure that the gizmo updates as much as possible outside of the world
if not util.IsInWorld(self:GetPos()) then
local velocity = (self:GetPos() - self.LastPos) / FrameTime()
size = DISTANCE_PADDING * (pl:GetPos() - self:GetPos()) + (PLAYER_WEIGHT * pl:GetVelocity() + GIZMO_WEIGHT * velocity)
end
-- Only set the collision bounds if it differs from our last size.
if self.LastSize ~= size then
self:SetCollisionBounds(-1 * size, size)
self.LastSize = size
end
self.LastPos = self:GetPos()
if not IsValid(pl) then return end
local plTable = RAGDOLLMOVER[pl]

View File

@ -4,8 +4,12 @@ ENT.Base = "base_entity"
function ENT:Initialize()
self.DefaultMinMax = Vector(0.1, 0.1, 0.1)
self.LastSize = self.DefaultMinMax
self.LastPos = self:GetPos()
self:DrawShadow(false)
self:SetCollisionBounds(Vector(-0.1, -0.1, -0.1), Vector(0.1, 0.1, 0.1))
self:SetCollisionBounds(-self.DefaultMinMax, self.DefaultMinMax)
self:SetSolid(SOLID_VPHYSICS)
self:SetNotSolid(true)