Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Checking if something is near object.

Discussion in 'Scripting' started by HKSpadez, Jan 28, 2016.

  1. HKSpadez

    HKSpadez

    Joined:
    Apr 24, 2013
    Posts:
    87
    Hey all,

    I have an enemy gameobject and i'd like for it to sidestep but first i have to check to see if theres a wall in the way or anything.

    I have 2 ideas on how to do this and would like to know which is more optimized?

    If i just put a collider next to him and check the collider for collision w/ the wall would that be ok? The other option i have is raycasting a line out of him maybe 3ft or so and checking to see that ray got any hits w/ the wall.

    Which method is better? My game is for android/gearVR so i'd like to get input on these 2 methods. or.. if theres any better way?
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    do you mean "instantiate a new game object with a collider attached"?

    raycast/spherecast sounds like it's going to win hands down.