Hello, I am starting a spell system and as I was testing I figured out something. My enemies have a detect range that I specify, but some spells casting range are higher then the enemies detect range. So with some spells I can hit the enemy until he dies and he will never pursue me. What would be a good way of making the enemy pursuing my player after being hit by the spell?
I would do something like this: Code (CSharp): void OnColliderEnter(Collider col) { if(col.tag == "spell") { //tag the spell projectiles as 'spell' //move the enemy towards the player } } If you put this on the enemy script, once a projectile with the tag "spell" hits it, you can call the movement method (or whatever code you use to move the enemy). Let me know if you have any more questions.
I use a function to damage the objects in my current project, and this function takes next to the amount and the type of damage a reference to the object that was the source of it as parameters.
Do you use a boolean to change states to show whether the enemy is in pursue mode? Could you use the col.tag from earlier and simply have it set this pursue flag to true? If not, what happens if your player moves inside the detect range, then manages to leave the detect range? Does your enemy stay in pursuit or stop?
I don't have a bool but I have a range check to engage the enemy to the pursue mode. If I enter the range and leave after the enemy goes back to wander around! I think I can try to override this with a bool state of pursue whenever the mob gets hit, turning it to true and making the enemy pursue the player regardless the range and whenever the enemy attacks it set this bool to false again, returning it to its normal behavior. Do you think that could work?
I'd set it up such that you do a check if the player has entered the engagement range, and if so set the boolean to true. Your pursue code can then completely ignore everything except the pursue boolean. Since its entirely focused on the boolean, it doesn't care why it was set, it only cares if it is set. This separation allows you the flexibility to have multiple ways to cause your enemies to engage in pursuit. You could do an additional check if they cross another larger range of when to disengage (set it to false). Dark Souls, as an example, has the engagement range based on the enemies current position but has the disengage range based on the level layout itself (and a limit on where the enemies will move to).
Sure. This is the signature of my function (I have defined this in an interface which anything that should be damaged has to implement): Code (CSharp): int Damage(Character damageSource, int amount, Weapon.DamageType damageType, int apPower, bool ignoreArmor); Nothing special, really. Character is a custom class that is central to my character system. I use the reference to give the character, who dealt the damage, experience relative to the damage dealt, but you can also use it to make the damaged entity aware of the attacker.