Jump to content

Pulse Effect Script


reepblue
 Share

Recommended Posts

Like the flicker script, this will modify an entities intensity to create a pulsing effect. If any improvements can be made, let me know!

 

Script.frequency=10.0--float "Frequency"
Script.Recursive=true--bool
function Script:Start()
self:SaveIntensity(self.entity,self.Recursive)
end
--Store the original intensity values
function Script:SaveIntensity(entity,recursive)
entity:SetKeyValue("Pulse_Intensity",entity:GetIntensity())
if recursive then
 local n
 for n=0,entity:CountChildren()-1 do
  self:SaveIntensity(entity:GetChild(n),true)
 end
end
end
--Apply a modified intensity value
function Script:ApplyIntensity(entity,intensity,recursive)
local i = entity:GetKeyValue("Pulse_Intensity")
if i~="" then
 entity:SetIntensity(tonumber(i) * intensity)
 if recursive then
  local n
  for n=0,entity:CountChildren()-1 do
   self:ApplyIntensity(entity:GetChild(n),intensity,true)
  end
 end
end
end
function Script:Draw()
if self.color==nil then
 self.color = self.entity:GetColor()
end

local alpha = Math:Sin(Time:Millisecs()/self.frequency)*0.25+0.75
self:ApplyIntensity(self.entity,alpha,self.Recursive) 
end

  • Upvote 5

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

It would be good if there was a delay before it flashed I think......then you could have a long time between short flashes, acting as a sort of visual hint rather than it seeming to be a continuously pulsing object (which may be jarring in a more realistic game).

 

Also I'd move the magic numbers (0.25 and 0.75) to the top and comment them and possibly expose them. It could be handy if the object went 50% brighter and 50% darker say.

 

I actually had a go at modifying it to do all this but got a bit bogged down and didn't complete it in the end. If I do I'll post it.

  • Upvote 1
Link to comment
Share on other sites

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.

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.

 Share

×
×
  • Create New...