Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Restrict object movement inside irregular shape

Discussion in '2D' started by BinarySouls, Dec 4, 2018.

  1. BinarySouls

    BinarySouls

    Joined:
    Jan 14, 2018
    Posts:
    2
    I want to restrict object movement inside an area. My object follows cursor position.

    I have already done that for the area border using Mathf.Champ to the translate because the borders are square shaped. The thing is that inside the box area there can also be other shapes which I don't want my object to go over.

    I know people suggest using physic collisions, but my game needs a position perfect positions so I can't use physics due to physics' offset colliders (the one physics use to detect collisions).

    Here is a short video of what I have:



    As you can see, movement is restricted (clamped) inside the box area but I want the movement to also be restricted in the black area.

    Is there a way to be able to do this with just clamping or do I need a raycast system or something like that?
     
  2. duffyhaha

    duffyhaha

    Joined:
    Aug 4, 2018
    Posts:
    1
    I assume that edge collides are the best/simplest solution here.