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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Moving around a static object

Discussion in 'General Discussion' started by harunkatirci, Jun 1, 2018.

  1. harunkatirci

    harunkatirci

    Joined:
    Nov 15, 2013
    Posts:
    10
    Hi everyone,

    I have an enemy (SAW) Saw is moving randomly on game area When saw hits the box with the green X position, I want to move the saw around the box. But how? Any suggestion?

    Thanks

    Untitled-1.png
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    First of all some questions:
    1. Do you know that the object will always be rectangular in shape?
    2. Will all enemy saws have the same radius- or can they be different sizes?
    For the moment, I am going to assume the answers are (1) yes and (2) same radius. So you could try something like this:
    1. Create 4 empty GameObject children on the cube.
    2. Place each at a corner of the cube offset (extending out in a straight line from the centre point) by the radius of the saw.
    3. Place a trigger collider on each of the 4 cube faces. Logically, each collider points to the corner child (from point 2) that is anti-clockwise from that collider.
    4. Now when a saw hits one of the colliders, set it on a move towards the linked child corner.
     
    harunkatirci, Tzan and angrypenguin like this.
  3. harunkatirci

    harunkatirci

    Joined:
    Nov 15, 2013
    Posts:
    10
    You made my mind clear thanks its done.
     
    Doug_B likes this.
  4. Martin_H

    Martin_H

    Joined:
    Jul 11, 2015
    Posts:
    4,433
    I would recommend doing pretty much this, but instead of colliders assign it the empty objects as waypoints and do all the corner checking in a script. I think that would be less prone to unexpected behavior, just a hunch. And likely easier to build more complex setups with multiple saws on different paths without them affecting each other.