I'm trying to make a resizable box. After fumbling through other people's code (and getting nowhere) I thought you guys might be able to help.
[lua]
if SERVER then
AddCSLuaFile("shared.lua")
end
ENT.Type = "anim"
ENT.Base = "base_anim"
ENT.PrintName = "Part"
ENT.Author = ""
ENT.Information = ""
ENT.Category = ""
ENT.Spawnable = true
ENT.AdminSpawnable = true
function ENT:SetupDataTables()
self:DTVar("Bool",0,"Anchored")
self:DTVar("Vector",0,"Size")
end
function ENT:SquareVector(Vec)
return Vector(Vec.x^2,Vec.y^2,Vec.z^2)
end
function ENT:Initialize()
local Size=self:GetDTVector(0)
if ( SERVER ) then
self.Entity:SetModel( "models/hunter/blocks/cube025x025x025.mdl" )
self:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics
self:SetSolid( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
self:PhysicsInitBox(-1*self:SquareVector(Size), self:SquareVector(Size))
self.Entity:SetCollisionBounds( -1*self:SquareVector(Size), self:SquareVector(Size) )
end
if ( CLIENT ) then
self.Entity:SetModelScale(Size)
self.Entity:SetRenderBounds(self:GetCollisionBounds())
end
end[/lua]
(That's the shared.lua of an entity, I did it all in that)
The model doesn't appear to correctly scale with the collision bounds. For instance, if the box is large the collision bounds extend over the box itself. If the box is small, the mode extends over the box. When using uneven proportions (e.g. 10,10,5) , not only does this have the aforementioned issue but the bounding box is rotated 90 degrees.
Sorry, you need to Log In to post a reply to this thread.