So, I was making a grenade swep, and, the grenade will spawn, fall to the ground, then a few seconds later, teleport to where ever it would land if thrown.
I added a trail on to it, and the trail flys normally save for a line between the lemon and trail
How do I fix?
[QUOTE=amkoc;29822329]So, I was making a grenade swep, and, the grenade will spawn, fall to the ground, then a few seconds later, teleport to where ever it would land if thrown.
I added a trail on to it, and the trail flys normally save for a line between the lemon and trail
How do I fix?[/QUOTE]
You should post the code or we cannot help you.
We aint all mind readers.
[QUOTE=Science;29823395]You should post the code or we cannot help you.
We aint all mind readers.[/QUOTE]
Durr, forgot.
I'm only going to post the attack function of the SWEP because the rest is just the Construction Kit's base (so I could have a lemon viewmodel)
[lua]function SWEP:PrimaryAttack()
self.BaseClass.ShootEffects (self);
//We now exit if this function is not running on the server
if (!SERVER) then return end;
//The next task is to create a physics entity based on the supplied model.
local ent = ents.Create ("lemon_grenade");
ent:SetModel (self.WorldModel);
ent:SetOwner(self.Owner)
ent:SetPhysicsAttacker(self.Owner)
ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16));
ent:SetAngles (self.Owner:EyeAngles());
ent:Spawn();
ent:Activate();
ent:SetKeyValue("targetname","lemon_"..tostring(ent:EntIndex()));
if(SERVER) then
local trail = util.SpriteTrail(ent, 0, Color(255,242,51), false, 15, 1, 0.5, 1/(15+1)*0.5, "trails/plasma.vmt")
end
//Now we need to get the physics object for our entity so we can apply a force to it
local phys = ent:GetPhysicsObject()
if phys:IsValid() then
phys:SetVelocity(Vector(1500,1500,1500) * self.Owner:GetCursorAimVector())
--phys:AddAngleVelocity(Vector(math.random(-1000,1000),math.random(-1000,1000),math.random(-1000,1000)))
else
print("lemon failure")
ent:Remove()
sprite:Remove()
end
//Now for the all important part of adding the spawned objects to the undo and cleanup data.
cleanup.Add (self.Owner, "props", ent);
undo.Create ("Lemon");
undo.AddEntity (ent);
undo.SetPlayer (self.Owner);
undo.Finish();
self.Weapon:SendWeaponAnim(ACT_VM_THROW)
timer.Simple(1,function() self.Weapon:SendWeaponAnim(ACT_VM_IDLE) end)
end
[/lua]
and the entity it launches:
[lua]
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Aperture Science Combustable Lemon"
ENT.Author = "KING OF SPACE"
ENT.Spawnable = true
ENT.AdminSpawnable = false
function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( self.Classname )
ent:SetPos( SpawnPos )
ent:SetOwner(ply)
ent:Spawn()
ent:Activate()
return ent
end
if CLIENT then
end
function ENT:Initialize()
if(CLIENT) then
killicon.Add( "lemon_grenade", "hud/happylemon2", Color( 255, 155, 155, 150 ) )
end
self.Entity:SetModel("models/gmstranded/props/lemon.mdl")
self.Entity:PhysicsInit(SOLID_VPHYSICS)
self.Entity:SetCollisionGroup(COLLISION_GROUP_NONE)
self.Entity:SetPos(self.Entity:GetPos())
local phys = self.Entity:GetPhysicsObject()
if phys:IsValid() then
phys:SetMass(0.5)
phys:Wake()
end
end
local function GravPickup( pl, ent )
if ent:GetClass() == "lemon_grenade" then
ent:SetParent()
end
end
hook.Add("GravGunOnPickedUp", "GravPickup", GravPickup);
function VecSub(v2,v1,v3)
vec=Vector(v3.x,v3.y,v3.z) --why did I make this function again
return vec
end
function ENT:PhysicsCollide( data, physobj )
if data.HitEntity:IsValid() then
if data.HitEntity:GetModel() != "models/gmstranded/props/lemon.mdl" then -- prevent lemon-on-lemon crash
data.HitEntity:Ignite(4,30) --burn, baby, burn!
timer.Simple(0.5, function()
ParticleEffectAttach("explosion_turret_fizzle",PATTACH_ABSORIGIN_FOLLOW,self,0)
ParticleEffectAttach("explosion_turret_fizzle",PATTACH_ABSORIGIN_FOLLOW,data.HitEntity,0)
end)
self.Entity:SetLocalVelocity(Vector(0,0,0))
self.Entity:SetParent(data.HitEntity)
self.Entity:SetPos(data.HitEntity:WorldToLocal(data.HitEntity:NearestPoint(self.Entity:GetPos()))) --when the lemons hit something, get as close as possible to it's model
timer.Simple(4, function() -- after four seconds, stop flames, and damage the attached entity
if self.Entity:IsValid() then
if self.Entity:GetParent():IsValid() then
self.Entity:StopParticles()
self.Entity:SetParent()
self.Entity:GetPhysicsObject():ApplyForceCenter(Vector(0,2,2))
local dmginfo = DamageInfo()
dmginfo:SetDamage( 150 ) dmginfo:SetDamageType( DMG_BULLET )
dmginfo:SetAttacker( player.GetAll()[1] )
dmginfo:SetDamageForce( Vector( 0, 0, 1000 ) )
dmginfo:SetInflictor(self.Entity)
data.HitEntity:StopParticles()
data.HitEntity:TakeDamageInfo( dmginfo )
end
end
end)
else
self.Entity:Remove() -- todo: find something more interesting to do when lemons touch
end
end
end
[/lua]
And screenshots:
[IMG]http://i55.tinypic.com/2hx26vp.jpg[/IMG]
[IMG]http://i52.tinypic.com/2rgclsn.jpg[/IMG]
So, when you shoot the lemon, it falls to your feet, but an invisible something flies in a nice arc, to which the lemon teleports after a few seconds, or sometimes not at all.
[LUA]ENT.PrintName = "Aperture Science Combustable Lemon"[/lua]
Yayyyy.
But have you thought of just modifying the current grenade weapon?
[QUOTE=Science;29837550][LUA]ENT.PrintName = "Aperture Science Combustable Lemon"[/lua]
Yayyyy.
But have you thought of just modifying the current grenade weapon?[/QUOTE]
what
I want it to do something completely different
Oh, i thought this was the error [I]"So, I was making a grenade swep, and, the grenade will spawn, fall to the ground, then a few seconds later, teleport to where ever it would land if thrown."[/I]
Not what you wanted it to do.
Science please dont attempt to help people in making SWEPS
[editline]15th May 2011[/editline]
We've all seen what you can do with a SWEP [i]which is nothing[/i]
OP you shouldn't just set the pos of where you want the nade to be you should apply force to it to make it look more realistic I suggest using
[b][url=http://wiki.garrysmod.com/?title=PhysObj.ApplyForceCenter]PhysObj.ApplyForceCenter [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Also Science get out you don't even understand basic lua you shouldn't be trying to help people because your failing badly
[lua]ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16));[/lua]
Instead you should use should use self.Owner:GetShootPos(). There won't be an issue with collisions as you've set the owner to the owner.
ent:SetPos(self.Owner:GetShootPos())
Now, when spawning it, you want to add velocity of the player's aim vector.
ent:SetLocalVelocity(self.Owner:GetAimVector()*10)
I'm not too sure about the value, so play about with it.
[QUOTE=FlapadarV2;29843167][lua]ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16));[/lua]
Instead you should use should use self.Owner:GetShootPos(). There won't be an issue with collisions as you've set the owner to the owner.
ent:SetPos(self.Owner:GetShootPos())
Now, when spawning it, you want to add velocity of the player's aim vector.
ent:SetLocalVelocity(self.Owner:GetAimVector()*10)
I'm not too sure about the value, so play about with it.[/QUOTE]
That made it teleport faster, but it's still doing it
[QUOTE=King Flawless;29843139]OP you shouldn't just set the pos of where you want the nade to be you should apply force to it to make it look more realistic [/QUOTE]
That's precisely the problem, I'm not.
When I launch it, an invisible item flies through the air the way I want the lemon-nade to, but the lemon model spawns, drops to the ground and does nothing for a few seconds, after which it teleports to the invisible object.
[lua]function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( self.Classname )
ent:SetPos( SpawnPos )
ent:SetOwner(ply)
ent:Spawn()
ent:Activate()
return ent
end[/lua]
Don't do that.
[editline]16th May 2011[/editline]
You want it to spawn at the players shoot pos, not where they're looking.
[QUOTE=FlapadarV2;29861510][lua]function ENT:SpawnFunction( ply, tr )
if ( !tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal * 16
local ent = ents.Create( self.Classname )
ent:SetPos( SpawnPos )
ent:SetOwner(ply)
ent:Spawn()
ent:Activate()
return ent
end[/lua]
Don't do that.
[editline]16th May 2011[/editline]
You want it to spawn at the players shoot pos, not where they're looking.[/QUOTE]
Doesn't that function only get called when you spawn it from the entity spawn menu?
Anyone? It's probably worth mentioning it actually does this when it's spanwed from the entities tab too
Sorry, you need to Log In to post a reply to this thread.