- Home /
A question about making spells(magic)
Hello there, I am trying to create a spell for my game that will basically do this: while the player is moving, the spell leave a trail of something that will give damage to enemies while they are standing on it (something like this: Shyvana Ulti)
So I am currently doing this: When the spell is activated, I take my player's position in a variable and controlling the distance between that position and player's current position. So basically, I instantiate a prefab(that is my spell) to world for every x unit my player moves on
As code:
void Update ()
{
if (Vector3.Distance(sneakAttackDropPos, transform.position) > sneakAttackDropDistanceConst)
{
sneakAttackDropPos = transform.position;
Instantiate(sneakAttackFX, transform.position, transform.rotation);
}
}
When I press [space] my sneakAttackDropPos is filled with my transform.position. sneakAttackDropDistanceConst this variable is the value of on every x units of my player moves, the spell should be instantiated, so its 1.5f and on every 1.5f unit of my player movement it instantiates my spell.
This works quite fine and as expected but here is the problem: I don't want my player to instantiate my spell on the ground where there is already a spell on it. Basically I don't want sneakAttackFX to be instantiated on same locations.
What have I tried to fix the problem: Controlled OnTriggerStay and OnTriggerExit in a script that has been attached to my sneakAttackFX object. So if my character is OnTriggerStay of my sneakAttackFX object, I false'd a variable and if that variable is false, my Instantiate will not work on player object, this has led to unexpected thus no good solution.
I have nothing else in my mind to fix this problem, so I am asking you this:
If this is a good way of doing something like this
If there is any, what are better options that can yield better results?
Thanks in advance.
Answer by Vonni · Apr 23, 2014 at 04:36 PM
I think you are on the right track, but I would not use any onTrigger or collision checks.
What I would do:
Activate spell.
Now check distance to spell
If distance is > constant, drop new spell
Now check for all spells
Basicly check distance to all spells positions stored in an array of some kind. Let me know if you dont know how that works.
GL
I though of trying something similiar to what you've said after I wrote here, So before I drop the spell, I will check if there are any spell near the player with OverlapCircleAllNonAlloc and drop the spell accordingly. Would that be fine solution on your opinion?
Sure, if are going to have a collider on the "spell/effect" anyway, then go for it. But probably faster to check distance.
What you actually offer is to control every single spell's distance to player's distance and if even one of them is smaller then my constant don't drop the spell, right?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Trouble Adjusting Stats (MP After Casting A Spell) 2 Answers
Distribute terrain in zones 3 Answers
Can I use Javascript (Unityscript) for Box2D for Unity or Farseer Physics? 1 Answer
C# Gravity Gun. Error CS0120 2 Answers