• set a models scale via axis using a Vector / EnableMatrix?
    6 replies, posted
Would like a code that will multiply or lengthen the object by its y axis. Any help is appreciated, thanks in advanced
clientside, affects the visuals but not the physics: [code] local scale = Vector(1,2,1) local matrix = Matrix() matrix:Scale(scale) someEntity:EnableMatrix("RenderMultiply",matrix) [/code] to scale the physics serverside, this will do it for you but on EVERY axis only: [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetModelScale]Entity:SetModelScale[/url] to scale physics serverside to specific axis manipulation: [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/PhysicsInitBox]Entity:PhysicsInitBox[/url] (but you have to have a boring box shape for the physics, and you have to figure out what the mins/maxs are yourself or via code) ((which means to first get the original mins,maxs of the OBB and to then scale the y component the same way you are in clientside visuals, and then apply all of these as the new physicsinitbox))
[code] function crabheadAttachment( Player ) local model = ents.Create("prop_dynamic") local scale = Vector(1, 2, 1) local matrix = Matrix() matrix:Scale(scale) model:EnableMatrix("RenderMultiply", matrix) model:SetModel("models/props_2fort/lunchbag.mdl") model:SetModelScale(Vector(1, 2, 1), 0) model:SetPos(Player:GetPos() + Vector(-5, -5, 65)) model:SetAngles(Player:GetAngles() + Angle(0, 0, 0)) Player:DeleteOnRemove(model) model:SetParent(Player) model:Spawn() model:Fire("setparentattachmentmaintainoffset", "Bip01_Head1", 0.01) end hook.Add("PlayerSpawn", "attachtobone", crabheadAttachment) [/code] Would it work like this? If not can you help fix which line of code is incorrect. [code] [ERROR] gamemodes/example/gamemode/core/shared/sh_attachment_system.lua:14: attempt to call method 'EnableMatrix' (a nil value) 1. v - gamemodes/example/gamemode/core/shared/sh_attachment_system.lua:14 2. unknown - lua/includes/modules/hook.lua:84 [/code]
enablematrix is clientside, as i said running it on client+server or just the server will cause an error it's only for the visuals
How would I go about using this on my shared file? if CLIENT then and etc?
a shared file isn't automatically going to run a function on the client and the server both it merely means the function of yours will be defined on both ends, not that running crabheadAttachment() serverside will automatically do it clientside
I've created two separate files, sv_attachment_system and cl_attachment_system, i've put the matrix code into the cl file and the spawnable item code into the SV but it doesn't seem to do anything. sv_attachment_system [code] function crabheadAttachment( Player ) if !Player:Alive() then return end local model = ents.Create("prop_dynamic") model:SetModel("models/props_2fort/lunchbag.mdl") model:SetPos(Player:GetPos() + Vector(-5, -5, 65)) model:SetAngles(Player:GetAngles() + Angle(0, 0, 0)) Player:DeleteOnRemove(model) model:SetParent(Player) model:Spawn() model:Fire("setparentattachmentmaintainoffset", "eyes", 0.01) end hook.Add("PlayerInitialSpawn", "attachtobone", crabheadAttachment) [/code] cl_attachment_system [code] local Entity = FindMetaTable("Entity") if !Entity then return end function Entity:SetModelScale(scale) local mat = Matrix() mat:Scale(scale) self:EnableMatrix("RenderMultiply", mat) end function clCrabHead() local model = ents.FindByClass("prop_dynamic") model:SetModelScale(Vector(1, 2, 1)) end [/code]
Sorry, you need to Log In to post a reply to this thread.