# How to make a mana station

Hey guys,

So I want to make a “mana station” in my game. So essentially it would be like a pillar in the level and the closer you get to it your mana would regenerate faster. The further away you get from it your mana would regenerate slower. I want the radius of the pillar’s mana regenerating capabilities to go through walls also.
I don’t even know how to start doing this. What I think would have to happen would be:

1. Raycast in all directions from the pillar
2. if the raycast hit a player then calculate how far away it is from the pillar
3. based on how far away the player is from the pillar then assign a percentage for mana regneration

Would that be the best way to do this? If so, how would I start coding that kind of raycasting?

Thanks!
Chris

Add a isTrigger collider to the pillar and add OnTriggerStay function to the pillars script. Once that trigger is entered then determine the distance between the player and its own transform position.

``````function OnTriggerStay(other:Collider)
{
if(other.CompareTag("Player"))
{
var dist=(other.transform.position-transform.position).magnitude;
manna+=(10-dist)*Time.deltaTime;
}
}
``````

This will give a maximum amount of 10 manna per second, granted if the collider covers a larger area you will need to increase that number then divide it by an amount to get the final additional manna value.

Lets say the dist is 100, 10-100 will give a negative value and thus subtract from the manna. If dist is 10, 10-10 is no manna and the closer you get the more manna you get. If dist 10 and the set value is 100, the 90 manna may be too high. So divide the end result before applying the manna.