edited March 2023 in General Support
generate combatants here I don't know why there is this inexplicable error, and I learned in 3d case inside the tutorial, the following picture, the component parameters are all default, I don't know why, all combatants are together? Instead of randomly generated within this collision body ......

image
https://imgur.com/a/jmQlhAS
Post edited by ranwang520 on
  • My current project is a 2d type game
  • Could you go into a bit of details on what I'm looking at here? And what you want to do?
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited March 2023
    Combatant Spawner Components 【2d】
    2d, generated combatants, it does not generate randomly within this collision body, but only at the edges of the collision body

    It's the same as the picture inside the link I posted above.
    The light green one is the collision body
    Post edited by ranwang520 on
  • Hm, might be a bug, I'll investigate.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
  • edited March 2023
    Yes, I have solved the problem through the source code, which is the GetRandomAdd() method under CombatantSpawner.cs


    Your 2d collision body judgement code uses the 3d code for random values, just change it as follows:




    protected virtual Vector3 GetRandomAdd()
    {
    Vector3 add = Vector3.zero;
    if(!this.settings.spawnAtPosition)
    {
    if(this.usedCollider != null &&
    this.usedCollider.enabled)
    {
    add.x += UnityWrapper.Range(-this.usedCollider.bounds.extents.x,
    this.usedCollider.bounds.extents.x);
    add.z += UnityWrapper.Range(-this.usedCollider.bounds.extents.z,
    this.usedCollider.bounds.extents.z);
    }
    else if(this.usedCollider2D != null &&
    this.usedCollider2D.enabled)
    {
    add.x += UnityWrapper.Range(-this.usedCollider2D.bounds.extents.x,
    this.usedCollider2D.bounds.extents.x);
    add.y += UnityWrapper.Range(-this.usedCollider2D.bounds.extents.y,
    this.usedCollider2D.bounds.extents.y);
    }
    }
    return add;
    }



    and the GetSpawnCenter() method also need to be modified


    ===============

    Although now under 2d it has been randomly generated within the range of the collision body, he will exceed this defined range ...... Although I have modified it to suit my use at the moment, there is still undeniably some problem, and I don't understand the code very well!
    Post edited by ranwang520 on
  • Will be fixed in the next update.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.