I want to weld the top entity to the bottom entity with lua.
Does anyone know what I'm doing wrong?
[IMG]http://i.imgur.com/yVjmTaf.png[/IMG]
[IMG]http://i.imgur.com/LILI8SF.png[/IMG]
Making a picture of the code is a very bad idea. Do you expect us to retype it to test it?
[QUOTE=Winter;45902484]I want to weld the top entity to the bottom entity with lua.
Does anyone know what I'm doing wrong?
[IMG]http://i.imgur.com/yVjmTaf.png[/IMG]
[IMG]http://i.imgur.com/LILI8SF.png[/IMG][/QUOTE]
You haven't told us what the problem is
[QUOTE=Coffeee;45905909]You haven't told us what the problem is[/QUOTE]
[QUOTE=Winter;45902484]I want to weld the top entity to the bottom entity with lua.
Does anyone know what I'm doing wrong? [/QUOTE]
Assuming the rotating blade at the top does not weld and either falls off or stays in midair?
[QUOTE=Angry pepper;45905942]Assuming the rotating blade at the top does not weld and either falls off or stays in midair?[/QUOTE]
Right, it simply doesn't weld.
The highlighted part in the picture is what I'm working on. When I spawn the entity the top will fall off and there are no errors. Here's the link to the wiki, [url]http://wiki.garrysmod.com/page/constraint/Weld[/url]
The code for the init.lua
[CODE]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel( "models/props_c17/lampShade001a.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:SetMass( 50 )
phys:Wake()
end
local ent = ents.Create( "turret_gun" )
if ( !IsValid( ent ) ) then return end
ent:SetPos( self:GetPos() + Vector(0,0,5) )
ent:Spawn()
constraint.Weld( self, ent, 0, 0, 0, false, false )
end
[/CODE]
Maybe constraints are removed after entity initialization? Try applying this after initialization is complete, with a manually called function.
[QUOTE=Winter;45939129]Right, it simply doesn't weld.
The highlighted part in the picture is what I'm working on. When I spawn the entity the top will fall off and there are no errors. Here's the link to the wiki, [url]http://wiki.garrysmod.com/page/constraint/Weld[/url]
The code for the init.lua
[CODE]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel( "models/props_c17/lampShade001a.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:SetMass( 50 )
phys:Wake()
end
local ent = ents.Create( "turret_gun" )
if ( !IsValid( ent ) ) then return end
ent:SetPos( self:GetPos() + Vector(0,0,5) )
ent:Spawn()
constraint.Weld( self, ent, 0, 0, 0, false, false )
end
[/CODE][/QUOTE]
I'd say your entity isn't valid until next frame.
local weld = constraint.Weld( self, ent, 0, 0, 0, false, false )
print( IsValid( weld ), type( weld ) )
try this:
timer.Simple( 0, function() if IsValid( ent ) && IsValid( self ) then constraint.Weld( self, ent, 0, 0, 0, false, false ) end end )
Sorry, you need to Log In to post a reply to this thread.