Search Unity

Magnet object that sticks to any nearest wall

Discussion in 'Physics' started by metamorphist, Apr 28, 2016.

  1. metamorphist

    metamorphist

    Joined:
    Mar 15, 2014
    Posts:
    77
    Need to have a magnet object that sticks to nearest wall.
    basically the object is invisible, it has the player's x and z position, and clamped within the player's height,
    it'll stick to any nearest walls/collider within a certain distance.. and particular tag.

    help?
     
  2. RedVonix

    RedVonix

    Joined:
    Dec 13, 2011
    Posts:
    422
    Perform a radial check using Phyiscs.OverlapSphere (http://docs.unity3d.com/ScriptReference/Physics.OverlapSphere.html) to get everything in-range, and filter based on the object's tag. Then knowing the nearby objects, choose one to stick to, do a raycast, acquire the point where the raycast hits the other object, then stick to that point.
     
  3. pauloaguiar

    pauloaguiar

    Joined:
    May 13, 2009
    Posts:
    700
    You can try follow this tutorial, probably help you:)
     
  4. metamorphist

    metamorphist

    Joined:
    Mar 15, 2014
    Posts:
    77
    Problem is that the objects now is pretty big... like environment.. giant statues, walls..
    To acquire that specific point to raycast? where? since the transfrom is located in the average middle of the concave mesh.

    What i think i need is, acquire the nearest normals, even before the raycast so i can create a force using the negative normal...... do you know how?
     
  5. metamorphist

    metamorphist

    Joined:
    Mar 15, 2014
    Posts:
    77