Search Unity

Is it possible to get collision detection working without rigidbodies?

Discussion in 'Physics' started by RayDawg, May 3, 2016.

  1. RayDawg

    RayDawg

    Joined:
    Mar 19, 2013
    Posts:
    108
    Currently, I have a click to move script that uses Vector3.MoveTowards() as my means to move a player character towards my clicked location in world space. However, Vector3.MoveTowards() ignores collisions.

    I tried using rigidbodies and when moving towards obstacles with colliders, the player character keeps bumping into the obstacle (I know why this is happening, I just don't know a good and efficient solution).

    What I just want the player character to do is to stop moving when they collide with an obstacle, but using Vector3.MoveTowards() is being finicky with rigidbody collisions.

    Is it possible to get collision detection working where I can stop a click to move player character on collision with an obstacle (without using rigidbodies)?
     
  2. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    Rigidbody.MovePosition is the alternative, and correctly colliding version of MoveTowards. Its not identical though, so make sure you understand the difference between what the two funcs are expecting.


    And will be 1000% easier to deal with over creating your own collision system. Unless you like complex maths.
     
  3. bart_the_13th

    bart_the_13th

    Joined:
    Jan 16, 2012
    Posts:
    498