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

Updating transform position in update causes objects to overlap

Discussion in 'Scripting' started by Scale01, Jun 18, 2019.

  1. Scale01

    Scale01

    Joined:
    Jun 18, 2019
    Posts:
    4
    Hi,

    I am having trouble with my game, I am updating object positions using transform.position each frame.
    And check if the position is free using raycasting before moving them.

    Yet i am having object going into the same tile...
    My guess is positions don't actually get updated until all updates having been done.

    Is this correct? Are there methods of solving this problem?

    tile.png
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,988
  3. Scale01

    Scale01

    Joined:
    Jun 18, 2019
    Posts:
    4
    Didn't help, the two objects still move into the same tile.
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,988
    those are physics objects? then how about FixedUpdate()
    and moving the rigidbody instead of transform.

    Or if its grid movement, the unit could reserve the spot (from array that keeps track of taken cells)
     
  5. Scale01

    Scale01

    Joined:
    Jun 18, 2019
    Posts:
    4
    No physics just raycasting to check for collisions.
    I was afraid this would be the answer, to make an array to hold all cell contents.

    Was really hoping i could force the transform position to take effect immediately, That would probably have been a simpler refactor.

    Thanks for the help!
     
  6. Scale01

    Scale01

    Joined:
    Jun 18, 2019
    Posts:
    4
    To answer my own question, after adding an array to keep track of taken cells which introduced a bunch of new bugs.

    I found out there is a project setting, that makes transform.position update immateriality...
     
  7. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    504
    What setting?