Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by sleepypixie · Jul 03, 2021 at 01:26 AM · spriteunity 2doffsetboxcollider2dpivot-point

How can I get my BoxCollider2D to stay centered on my sprite?

The problem: After I start my game, the player's BoxCollider2D's y offset changes.
.
Details: It started after I changed the pivot point of the player's sprite from center to bottom center. I did this in order to make the player's death animation, which is a simple 90 degree rotation. Unfortunately, if the issue did occur before the animation was made, I didn't catch it in a quick play test.
Now during the game, the collider seems to shift downward about half of its length. Weirdly, that lowered position is the shape of what collides in the game and what the debug logs show, but the collider always appears in the correct position in the inspector and scene view.
.
Debug log findings: I don't have anything in my code that directly changes the collider's offset, yet debug logs are showing different values for the collider's y offset.
It's in the same correct position which I see in my inspector during the game manager's awake function, then is moved half of its length downward in my mover script's start function. That script does get the BoxCollider2D component, but the debug log shows that the offset is incorrect before the script has even gotten it. That's the only script that touches it, but it doesn't use the offset. The player's start function then prints the correct value, and then my NPC's script grabs the value to print it, and shows the lower/incorrect offset.

.
Tried so far: I tried changing the BoxCollider2D's offset in the inspector to counteract the problem, but then during the game, it snaps into the same y value regardless of my changes.
I changed only the player's transform's rotation in the animation. The box collider does not appear to be errantly rotated during run time, just lowered. I tried running the game with the animator disabled, and the same issue occurred. I tried changing the sprite's pivot point back to the center and adjusting the box collider. It snaps into the same lower position. I didn't include code because I didn't change the scripts around the time the issue started, and I'm not sure which could be the culprit since none mess with the offset. Let me know if you'd like to see code though, I can post it.
.
I hope someone has a fix for this problem. Thank you so much!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Devster2020 · Jul 03, 2021 at 08:08 AM 0
Share

Hello @sleepypixie , can you post any screenshots please?

avatar image logicandchaos · Jul 03, 2021 at 01:54 PM 0
Share

can you show your player in the inspector?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ZeyFight · Jul 03, 2021 at 02:43 PM

Hmm ... I think we have to put back the pivot correctly and create a death animation without touching the player ... That is to say without modifying the pivot or other directly from the inspector. And lifted your player if you have gravity so that it falls back into place

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by sleepypixie · Jul 03, 2021 at 04:23 PM

While taking screenshots for the above questions, I realized that I made a mistake in playtesting. Changing the sprite's pivot point back to the center does solve the problem. The player sprite is selected at the beginning of the game, and I somehow forgot to move the point back to center on the sprite I play tested with the first time. That could explain the collider offset changing during runtime, too. It will be easy enough for me to continue on with making my game with the original centered pivot point.

I am still curious to know why moving the sprite's pivot point moved the box collider if anyone happens to know.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

159 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sprite tiling and offset? 3 Answers

How do I randomly spawn objects in 2D game? 0 Answers

How click and drag a 2D game object without click and dragging the Camera Orthographic? 1 Answer

Set Texture SpriteMode pivot point via script 0 Answers

Does PolygonCollider2D.OverlapPoint() perform differently in Unity player than an Android device? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges