Search Unity

How to match gameobject size to OverlapSphere radius.

Discussion in 'Scripting' started by nakamagaming10, May 30, 2020.

  1. nakamagaming10

    nakamagaming10

    Joined:
    Aug 4, 2019
    Posts:
    2
    Hi.
    i'm working on a game feature involving AoE attacks and i can't find a way to match the graphic effects to the precise size of the area involved. i have my attack, which is a scriptable object attached to my player, the attack uses OverlapSphereNonAlloc to catch the colliders of enemies in range. when i trigger OverlapSphere i also instantiate the graphical effect of the attack (a game object with a particle system and particle systems in it's children).
    I'm struggling to find a way to make sure that the effect is always the same size as the OverlapSphere. i have the radius (float) of the sphere, i tried ParticleSystem.startSize = OverlapSphere.radius but it only keeps the effect "proportionate" with the size of the sphere, it doesn't match their size.
    i cannot use Bounds because i have no renderer and no mesh on the effect gameobject.

    anyone would know how to solve this problem?

    i uploaded 3 pictures of my player attacking with different AoE sizes. the yellow sphere is the wiresphere gizmo matching the size of my OverlapSphere and the purple particles are the effect which size i want to match the sphere.
     

    Attached Files:

  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    Make the size of your effect 1.0, then startSize will proportionately scale it to match the other size.
     
  3. nakamagaming10

    nakamagaming10

    Joined:
    Aug 4, 2019
    Posts:
    2
    what do you mean by changing the size of the effect?


    as i'm testing i realize that i can't do this by changing the size of the particle systems, some of them need to have startSize changed, others need shape.radius to change. it doesn't seem like a viable solution. i'm trying the "doing this from the localScale" road now.
    thanks for the help.