So I'm working on this entity and since I'm fairly new to LUA coding, how do I make objects move? All I really need is for it to move forward constantly.
Now it doesn't spawn at all. :frown: Heres the code if any one can figure out what I did wrong. [code]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
function ENT:Initialize()
self:SetModel("models/1-UP.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end
end
function ENT:SpawnFunction(ply, tr)
if ( !tr.Hit ) then return end
local ent = ents.Create("ent_1up")
ent:EmitSound(table.Random(spawnsounds), 100, 100)
ent:SetPos(tr.HitPos + tr.HitNormal * 16)
ent:Spawn()
ent:Activate()
local trace = self.Owner:GetEyeTrace()
trace.Entity:SetVelocity(=ENT:GetForward() * 500 + Vector(0,1000,0))
return ent
end
ents.Create("prop_physics")
--prop.SetPos(Vector(0,0,0))
spawnsounds={
"1upsounds/powerup.wav"
}
usesounds={
"1upsounds/1-up.wav"
}
function ENT:Use( activator, caller )
self.Entity:Remove()
if ( activator:IsPlayer() ) then
local health = activator:Health()
activator:SetHealth( 100 )
self:EmitSound(table.Random(usesounds), 100, 100)
end
end
[/code]
[lua]function ENT:SpawnFunction(ply, tr)
if ( !tr.Hit ) then return end
local ent = ents.Create("ent_1up")
ent:EmitSound(table.Random(spawnsounds), 100, 100)
ent:SetPos(tr.HitPos + tr.HitNormal * 16)
ent:Spawn()
ent:Activate()
-- local trace = self.Owner:GetEyeTrace() You already have a trace... tr
-- trace.Entity:SetVelocity(=ENT:GetForward() * 500 + Vector(0,1000,0)) -- I think you want to set velocity of this ent. (the = shouldn't be there)
ent:SetVelocity(self:GetForward() * 500 + Vector(0, 1000, 0)) -- self not ENT
return ent
end
-- ents.Create("prop_physics") Why are you doing this?
-- prop.SetPos(Vector(0,0,0))[/lua]
Sorry, you need to Log In to post a reply to this thread.