For the past two hours I've tried making this ball that i can pick up and throw ( I don't know why ). So far I've made so you can pick up the ball, but I've been stuggling with the throw part, so i was hoping someone could help me. This is my code(Sorry for the messy code):
[code]
function ENT:Initialize()
self:SetModel("models/roller_spikes.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self.CanUse = true
local phys = self:GetPhysicsObject()
phys:Wake()
end
function ENT:Think()
//self:SetPos(self:GetPos() + Vector(0, 0, math.sin(CurTime())*-1.5))
//self:SetAngles(self:GetAngles() + Angle(0,50,0))
if IsValid(self:GetParent()) then
local pl = self:GetParent()
if pl:KeyDown(IN_ATTACK2) and pl:IsOnGround() then
self:SetParent(nil)
end
end
end
function ENT:OnTakeDamage()
self:Explode()
self:Remove()
end
function ENT:Touch( hitEnt )
if ( hitEnt:IsValid() and hitEnt:IsPlayer() and hitEnt:Alive() ) then
//hitEnt:SetHealth(1000)
//self:Remove()
self:SetParent(hitEnt)
self:EmitSound("vo/npc/male01/imhurt01.wav")
self:SetSolid( SOLID_NONE )
//hitEnt:SetVelocity(Vector(0,0,1000))
self.Entity:Fire("setparentattachment", "anim_attachment_RH", 0)
end
end
function ENT:Explode(hitpos, hitnormal)
self:NextThink(CurTime())
hitpos = hitpos or self:GetPos()
hitnormal = (hitnormal or Vector(0, 0, -1)) * -1
util.ScreenShake(hitpos, 500, 0.5, 1, 300)
local effectdata = EffectData()
effectdata:SetOrigin(hitpos)
effectdata:SetNormal(hitnormal)
util.Effect("barrelexplosion", effectdata)
end
[/code]
Thanks for any help that you might give me.
[QUOTE=Handsome Matt;43825096]what is the error
what is the result
what is the intended result[/QUOTE]
1. No error.
2. Nothing happens
3. I want it to unparent from my player and shoot the ball forward. (when i right click).
Thanks.
try something like this
[LUA]
function ENT:Think()
if IsValid(self:GetParent()) then
local pl = self:GetParent()
if pl:KeyDown(IN_ATTACK2) and pl:IsOnGround() then
self:SetParent(nil)
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:ApplyForceCenter( pl:GetAimVector() * 3000 )
end
end
end
end
[/LUA]
[QUOTE=rejax;43829827]try something like this
[LUA]
function ENT:Think()
if IsValid(self:GetParent()) then
local pl = self:GetParent()
if pl:KeyDown(IN_ATTACK2) and pl:IsOnGround() then
self:SetParent(nil)
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:ApplyForceCenter( pl:GetAimVector() * 3000 )
end
end
end
end
[/LUA][/QUOTE]
Thank you for replying. It's kinda working. It's clearing the parent, but it's not shooting the ball forward. When i right click it's just floating in the air.
Edit: I think i know why it doesn't work, but i can't think of a solution. It's because when i pick it up it sets the entity's solid to SOLID_NONE. If i change that to solid_vphysics it's just gonna get stuck in the player.
Ah, thanks Matt. This seems to have fixed my problem.
Sorry, you need to Log In to post a reply to this thread.