Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[Quick Question] Dropped Item Pickup - Should character or dropped item check for collision?

Discussion in 'Scripting' started by AbandonedCrypt, Jan 14, 2021.

  1. AbandonedCrypt

    AbandonedCrypt

    Joined:
    Apr 13, 2019
    Posts:
    63
    Hey I am currently scratching my head over this teeny tiny question:

    Right now I'm casting an
    OverlapSphere
    with radius
    pickupRadius
    from my character to check for
    Item
    s laying on the ground and picking them up.

    However just last night I thought that I am doing a lot of unnecessary Sphere casts whenever there are no dropped items around. So I thought about moving the Sphere Cast to the dropped items, have them cast an
    OverlapSphere
    with radius
    pickupRadius
    , check for
    Player
    and on collision add themselves to the inventory.

    Right now I'm unsure which approach is better, since due to the hack'n'slash nature of the game, there can be many situations with an excess of items laying about, which are not going to be picked up. Ofc they will have a despawn timer, but still.
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    4,805
    Definitely better for the player to do it. One overlapSphere vs many.

    You could also just use trigger colliders instead of overlapSphere
     
    AbandonedCrypt likes this.
unityunity