Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    73
    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:
    7,888
    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.