lxFirebal69xl Posted December 21, 2016 Share Posted December 21, 2016 So, when the player gets below a certain amount of health this happens: if self.health < 50 then self.camera:AddPostEffect("Shaders/PostEffects/radiation.shader") end Calls a simple shader to the camera, and this works without issues. Now the thing is, I made this function. function Script:CameraFix() if self.health > 50 then self.camera:ClearPostEffects() end end Which gets called every time the player picks up a health item in the game. Here's a video demonstrating what happens when I grab a health item and the CameraFix() is called. Quote Link to comment Share on other sites More sharing options...
macklebee Posted December 21, 2016 Share Posted December 21, 2016 Is that radiation post effect only being added once or is it being added multiple times when the player health is below 50? Just curious because the code above implies you are constantly adding the same effect to the camera effect stack. Not quite sure why CleatPostEffects() is causing the scene to bleed but you could try to use the RemovePostEffect() command. Assuming you are only adding this one post effect to the stack then you could remove it via its number in the stack. self.camera:RemovePostEffect(0) Looking at this now - it would be helpful if Josh gave us a way to count the number of post effects in the stack. Something like 'camera:CountPostEffects()'? Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted December 21, 2016 Author Share Posted December 21, 2016 Is that radiation post effect only being added once or is it being added multiple times when the player health is below 50? Just curious because the code above implies you are constantly adding the same effect to the camera effect stack. Not quite sure why CleatPostEffects() is causing the scene to bleed but you could try to use the RemovePostEffect() command. Assuming you are only adding this one post effect to the stack then you could remove it via its number in the stack. self.camera:RemovePostEffect(0) Looking at this now - it would be helpful if Josh gave us a way to count the number of post effects in the stack. Something like 'camera:CountPostEffects()'? Using the self.camera:RemovePostEffect(0) Does indeed fix the issue, but doesn't remove the radiation post effect, so I guess I'm calling it multiple times, don't know how though since this if self.health < 50 then self.camera:AddPostEffect("Shaders/PostEffects/radiation.shader") end Only gets called when the player is hurt, aka in the Hurt() function. Quote Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted December 21, 2016 Author Share Posted December 21, 2016 Medkit script: Script.health = 50.0 --float "Health" Script.useOnce = true --bool "Use once" Script.ObjectDescription = "I'm not hurt." --string "Object Description" Script.enabled = true --bool "Enabled" Script.soundfile=""--path "Sound" "Wav Files (*.wav):wav" local font1 = Font:Load("Fonts/MODERN SERIF ERODED.ttf", 20) function Script:Start() if self.soundfile then self.sound = Sound:Load(self.soundfile) end if self.health < 0 then error ("Health can't be a negative value.") end end function Script:Use(player) if player.health < player.maxHealth then self.enabled = false if self.sound then self.sound:Play() end player.health = self.health + player.health player:CameraFix() if self.useOnce then self.entity:Release() end elseif self.enabled == true then self.component:CallOutputs("Use") self.ObjectDescription = "Much better now." self:GetText() end end function Script:GetText() if self.enabled == true then return self.ObjectDescription end end function Script:Enable()--in self.DisplayEnabled=true end function Script:Disable()--in self.DisplayEnabled=false end Hurt script: function Script:Hurt(damage,distributorOfPain) if self.health>0 then self.sound.damage[math.random(#self.sound.damage)]:Play() self.health = self.health - damage self.hurtoffset = Vec3(math.random(-1,1),math.random(-1,1),0):Normalize()*30 local blood = {} local n=1 blood.texture=self.image.blood[math.random(1,4)] blood.intensity=1 table.insert(self.bloodoverlay,blood) if self.bloodindex>4 then self.bloodindex=1 end if self.health<=0 then self:Kill() end end if self.health < 50 then self.camera:AddPostEffect("Shaders/PostEffects/radiation.shader") end end Code that is called when medkit is used: function Script:CameraFix() if self.health > 50 then self.camera:RemovePostEffect(0) end end Quote Link to comment Share on other sites More sharing options...
macklebee Posted December 21, 2016 Share Posted December 21, 2016 If the hurt function is being driven by a collision then it probably is being added multiple times. A system print would determine this. But the code you are showing will mean the same effect would be added each time the Hurt function is called and the player health is below 50. You need to add a boolean check to see if the post effect has already been added and to prevent it from being added multiple times. if self.health<50 and self.postadded=="false" then self.camera:AddPostEffect("Shaders/PostEffects/radiation.shader") self.postadded = true end function Script:CameraFix() if self.health>50 and self.postadded=="true" then self.camera:RemovePostEffect(0) self.postadded = "false" end end Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Josh Posted December 21, 2016 Share Posted December 21, 2016 AddPostEffect() returns an integer. Make sure this number isn't going up and up and up each time you add that effect. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted December 21, 2016 Share Posted December 21, 2016 Do you have any other post-effects added on the camera? AddPostEffect adds them to the back of the stack. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted December 21, 2016 Author Share Posted December 21, 2016 I was able to fix this by using: self.camera:RemovePostEffect(4) It was counting the root shaders. 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted December 22, 2016 Share Posted December 22, 2016 Be careful because you might change the number of shaders later. I would only add/remove one shader dynamically because it can get complicated. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
lxFirebal69xl Posted December 22, 2016 Author Share Posted December 22, 2016 Be careful because you might change the number of shaders later. I would only add/remove one shader dynamically because it can get complicated. Yeah, agree, this is the only shader I'm thinking of using for the game that's dynamic. So I guess I can do it this way without problems. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.