• 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
Question by bodicpen · May 10, 2017 at 03:58 PM · collisionmovementcolliderpositionlooping

Transforming position for different colliders for repeating background?

In my main camera, I have a BoxCollider2D (looper) as a child. It is set up far to the left of the camera. The camera is following my player. I have 6 background panels and 7 ground panels. These grounds and background have a trigger boxcollider on them so whenever the 'looper' collides with the trigger background, that background would go up front of the last background, repeating it. However, my ground is shorter than my background so i'm having a bit of trouble. The background transforms position well but the ground seems to overlap each other. I know there's something missing. I'm totally new to unity, about a week old now. I have thought of a solution wherein I would make my ground panels as long as the background panels so they would change position at the same time but I still want to figure this one out since I want to learn. Check my script.

      int bgPanels = 6; // Number of our background.
 void OnTriggerEnter2D(Collider2D collider) { 
     float sizeOfBGObject = ((BoxCollider2D)collider).size.x; // The size of a background is equal to the size of the collider.
     Vector3 pos = collider.transform.position;
     pos.x += sizeOfBGObject * bgPanels; // The size of the background multiplied by the number of how many backgrounds are there, this way it would go next of the last background.
     collider.transform.position = pos; // We change the position of the collider to the result of 'pos'
 }

I know what's going on. The ground is moving too, but since it's shorter and there's seven of them, the size of the ground is just being multiplied by 6 instead of 7 that's why there are overlaps. I just want to know if somehow I can tell the collider "If you collided with the background, the position would be equal to the size of it multiplied by 6 but if you collided with the ground, the position would be equal to the size of it multiplied by 7". Thank you so much! :)

Comment

People who like this

0 Show 0
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Object collider not operating properly 2 Answers

Help with 2D point and click move script that will stop moving when it hits a wall 1 Answer

rigidbody It's going up and bounces when is moving 1 Answer

player collite with object and start moonwalking 1 Answer

Collision Issue - Walk Through Object 0 Answers


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