I’m making a Tower Defense game, I know everything about it, but the only thing I don’t know is how do I make a shadow mob? So, for example, consider a shadow mob, and if that tower doesn’t have invisible vision, I don’t want it to hit the shadow mob, how will it be?
Let’s say you give shadowMobs a specific attribute called ‘isShadow’, with the value being true.
Now when you shoot make sure that they have that attribute.
if distance <= range and not target:GetAttribute("isShadow") or (target:GetAttribute("isShadow") and tower:GetAttribute("canSeeShadow")) then
...
end
So if the target is not a shadow then it gets ran normally.
If the target is a shadow and your tower can see the shadow then it gets ran normally as well.
You can give him a Tag or have some other way of tracking which mob is invisible to towers and which isn’t.
After that, it’s pretty much just an if statement:
function Shoot(enemy: Model)
if CollectionService:HasTag(enemy, "Invisible") then -- Check if enemy is invisible
if ... then -- Check if tower has capability to damage invisible
Damage(enemy, ...)
end
else
Damage(enemy, ...)
end
end
Thank you bro,I am grateful, actually it’s easy, i’m just a bit of a stup…d
this is very useful i will use one of your two thanks for your help.
If you would like me to I can give you a longer explanation on what I did.
so i will try if i can’t i will ask you
So of course if you want it don’t bother, thank you very much for asking
Alright please send the current code you have for detecting a nearby enemy first then we can get started.
You will need to give the shadow mobs the attribute called "isShadow" with the boolean value true. You can do this via scripting or when you set up the inital mob.
ShadowMob:SetAttribute("isShadow", true)
Then for towers who can hit enemies they’d need the attribute "shadowVision", this allows them to see shadows.
ShadowTower:SetAttribute("shadowVision", true)
Now you want to make sure the enemy is not a shadow, if they then the tower has to have shadowVision.
if not enemy:GetAttribute("isShadow") then
end
That is the normal code, but now let’s check if you got shadowVision.
if not enemy:GetAttribute("isShadow") or tower:GetAttribute("shadowVision") then
So if the tower has shadowVision then they will be able to see any mob regardless if they are shadow or not.
I’m not into coding right now but I will soon. I have school now, when the school is over, I will write you via dm or here.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.