Jump to content
Thirsty Panther

Problem with pistol prefab

Recommended Posts

I'm creating a FPS game but I've run into a problem with the Pistol prefab.

 

I have a health bar for the player ( from Aggrors video tutorials) and every time I fire the pistol the health bar flashes simultaneously with the muzzle flash.

 

Any help would be appriciated.

Share this post


Link to post

Update: I've ruled out the Player Health Bar overlay as the problem. I thought it may have something to do with the Alpha channel. I also changed the colours of the Health Bar to no effect.

 

The scripts are as follows:

Pistol:

 

function Script:Draw()

local t = Time:GetCurrent()

 

if self.muzzlelight:Hidden()==false then

if t-self.firetime>50 then

self.muzzlelight:Hide()

end

end

 

local jumpbob = 0

 

if self.jumpoffset<0 then

jumpbob = (Math:Sin(self.jumpoffset))*0.01

self.jumpoffset = self.jumpoffset + 8

end

 

if self.landoffset<0 then

jumpbob = jumpbob + (Math:Sin(self.landoffset))*0.01

self.landoffset = self.landoffset + 10

end

 

--Animate the weapon

local bob = 0;

local speed = math.max(0.1,self.player.entity:GetVelocity():xz():Length())

if self.player.entity:GetAirborne() then speed = 0.1 end

self.swayspeed = Math:Curve(speed,self.swayspeed,20)

self.swayspeed = math.max(0.5,self.swayspeed)

self.amplitude = math.max(2,Math:Curve(speed,self.amplitude,20))

self.timeunits = self.timeunits + self.swayspeed*4*Time:GetSpeed()

local sway = math.sin(self.timeunits/120.0) * self.amplitude * self.maxswayamplitude

bob = (1-math.cos(self.timeunits/60.0)) * self.maxswayamplitude * 0.1 * self.amplitude

local campos = self.player.camera:GetPosition(true)

 

self.smoothedposition.x = campos.x

self.smoothedposition.y = Math:Curve(campos.y,self.smoothedposition.y,2)

self.smoothedposition.z = campos.z

 

self.entity:LockMatrix()

self.entity:SetPosition(sway*self.entity.scale.x,bob+jumpbob,0)

self.entity:Translate(self.offset.x,self.offset.y,self.offset.z)

self.animationmanager:Update()

self.entity:UnlockMatrix()

end

 

Health Bar:

 

 

function Script:PostRender(context)

 

--background

context:SetColor(self.backgroundColorFractioned)

context:DrawRect(self.offset.x, context:GetHeight() - self.offset.y, self.size.x, self.size.y)

 

--healthbar

context:SetColor(self.healthbarColorFractioned)

local healthFactor = self.player.script.health / self.player.script.maxHealth

context:DrawRect(self.offset.x,context:GetHeight() - self.offset.y, self.size.x * healthFactor, self.size.y)

 

--Draw overlay

if self.overlay ~= nil then

context:SetBlendMode(Blend.Alpha)

context:SetColor(1,1,1,1)

context:DrawImage(self.overlay, 0, context:GetHeight() - self.overlay:GetHeight())

context:SetBlendMode(Blend.Solid)

end

end

 

Both these scripts are unaltered from Leadwerks (Pistol prefab) and Aggror (Player Health Bar).

 

Thanks.

Share this post


Link to post

Health Bar:

 

 

function Script:PostRender(context)

 

--background

context:SetColor(self.backgroundColorFractioned)

context:DrawRect(self.offset.x, context:GetHeight() - self.offset.y, self.size.x, self.size.y)

 

--healthbar

context:SetColor(self.healthbarColorFractioned)

local healthFactor = self.player.script.health / self.player.script.maxHealth

context:DrawRect(self.offset.x,context:GetHeight() - self.offset.y, self.size.x * healthFactor, self.size.y)

 

--Draw overlay

if self.overlay ~= nil then

context:SetBlendMode(Blend.Alpha)

context:SetColor(1,1,1,1)

context:DrawImage(self.overlay, 0, context:GetHeight() - self.overlay:GetHeight())

context:SetBlendMode(Blend.Solid)

end

end

 

Both these scripts are unaltered from Leadwerks (Pistol prefab) and Aggror (Player Health Bar).

 

Thanks.

 

Does putting context:SetBlendMode(Blend.Alpha) right at the start of the postrender function help?

Share this post


Link to post

Also tip for the guy that spent a lot of time trying to fix issues. When you set the blend mode to alpha at the end of that function set the blend mode back to solid. I have had other rendering issues due to not setting the blend modes properly, typically when more than one script is using context.

Share this post


Link to post

Thanks for the tip BH. I'm starting to see how every problem overcome is a valuable learning experience.

Just a few weeks ago I thought I would never get this but already I'm fixing things and learning fast. I know

I'm a long long long way away but every time I think that I learn something new and the motivation sticks.

Never thought it could be so frustrating wanting to learn everything yesterday. Why wasn't it like that

back in school wink.png. Of course I have many of you to thank for your help so thanks again!

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...