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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Collision box changes position when running

Discussion in '2D' started by ThierryC, Sep 14, 2015.

  1. ThierryC

    ThierryC

    Joined:
    Sep 14, 2015
    Posts:
    9
    I tried different tutorial and then tried to apply it to a very small project.
    My problem is that the collision box I defined around the player sprite changes its position at runtime.
    Here are two screenshots: during design and during runtime.

    Is this a common newbie error?

    Thanks for any clue.
     

    Attached Files:

  2. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Can you attach a screenshot of your inspector for the sprite, & do you have any scripts running or is the 2nd screenshot showing what happens when all you have in the scene is the sprite & no scripts attached?
     
  3. ThierryC

    ThierryC

    Joined:
    Sep 14, 2015
    Posts:
    9
    I have scripts to handle movement and animation.
    If it's useful, I don't mind to share the whole project, but is it possible just with the forum upload method ?
     
  4. ThierryC

    ThierryC

    Joined:
    Sep 14, 2015
    Posts:
    9
    I try a zip of the project here
     

    Attached Files:

  5. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I can't open them on the iPad, a screenshot of the scene showing the inspector should help
     
  6. ThierryC

    ThierryC

    Joined:
    Sep 14, 2015
    Posts:
    9
    Here it is.
     

    Attached Files:

  7. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    No idea, it looks fine to me & I've never had this issue. I have had the problem of confusing myself with the collider & the outline of the sprite but this looks like your collider is resetting to the centre of your sprite. Do the collider size&/or x/y axis numbers change in the inspector when you run the scene?

    I've also had the issue where the animation runs ahead of the character controller & collider. If you disable the animator, or remove it, & drag the character up does the collider change when the character is falling to the ground? If the collider stays around the player when there's no animation then that could indicate where your issue is.
     
  8. leoyaik

    leoyaik

    Joined:
    Oct 13, 2014
    Posts:
    6
    Hi

    This is because your sprites have different pivot settings.

    In the GameObject SpriteRenderer the sprite (astroWalkRight) has the pivot on top left while the sprites used in the animation has the pivot set to center.

    Cheers
     
  9. ThierryC

    ThierryC

    Joined:
    Sep 14, 2015
    Posts:
    9
    I think I understand what you wrote, now I need to understand with Unity open to see where those pivot settigns are.
    Thanks anyway, it gives me something to search and try
     
  10. ThierryC

    ThierryC

    Joined:
    Sep 14, 2015
    Posts:
    9
    Thanks a lot Leoyalk, i just add to open the sprite editor to fix the pivot, remove the offset I tried in the collision box and everything is perfect now.
     
  11. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,563
    theANMATOR2b likes this.
  12. ThierryC

    ThierryC

    Joined:
    Sep 14, 2015
    Posts:
    9
    This will become awesome when I will have enough nights to enjoy Unity long enough to code the entire game ;)
     
    MelvMay likes this.
  13. ThierryC

    ThierryC

    Joined:
    Sep 14, 2015
    Posts:
    9
    Now, I have to figure out how to handle the fact that moving out from right will continue on the left and vice versa.
     

    Attached Files:

  14. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Do a position check & then transform.position the player to the other side of the screen or try doing it when it isn't visible by the camera anymore if the camera doesn't follow the player.
     
  15. ThierryC

    ThierryC

    Joined:
    Sep 14, 2015
    Posts:
    9
    That's what I've done.
    For the moment, it will be enough. I'll see later if I try a more complex behavior with some cloned sprite.
    Maybe it's time for me to open a post in the Work In Progress section ;)

    PS: I know, my Gif is not at the right resolution ;)
     

    Attached Files:

    theANMATOR2b likes this.