Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Kyme Wong · Aug 13, 2014 at 09:24 PM · collidertriggerphysics2dscroll

How to scroll the background in a 2D game

I'm creating a simple 2D scroll game (like flappy bird, character goes all the way to the right and the background & obstacles are automatically and repeatedly generated)

I created three backgrounds, left, middle and right, and place them next to each other. A script called scrolling is added to each background. The script goes:

 public GameObject next
 public int distance
 
 void  OnTriggerEnter2D(Collider2D c){
     next.transform.Translate(new Vector3(distance,0,0));
     Debug.Log("enter");
 }

"left" acts as next for right, right for middle, and middle for left, so they pave the road ahead in turn on and on. A Physics2D trigger is placed on the background (which is a rectanglular sprite), as well as a circle collider on the main character. However, when the character enters...nothing at all happened. Even the log did not show. Does anyone know why this happened?

Or, after I rethought about it, would the reason be that I simply "translate" the main character to make it move in one direction? Since I want him to move uniformly in x direction. But would this make him a kinematic object, so that the collision with the trigger doesn't count?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Endless_Aftermath · Aug 13, 2014 at 09:57 PM

If the script posted above is on the background, then the Collider2D should be on the character, right? And it should have an option in the inspector for "Trigger", I think. I usually work with 3D and this is the way it works there. OR you could try putting the script above on the character, just change the code a bit to look like this...

 void OnTriggerEnter2D(Collider2D c)
 {
      c.transform.Translate(new Vector3(distance,0,0));
      Debug.Log("enter");
 }//end of OnTriggerEnter2D()
Comment
Add comment · Show 1 · 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 Kyme Wong · Aug 13, 2014 at 10:43 PM 0
Share

no...actually the trigger is on the background, and the character has the collider. (since if both are colliders than character would bounce off the space) And what I would like would be to move the background so that the space infinitely extends, ins$$anonymous$$d of translating the main character himself.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Can't click gameobject when over another trigger? 1 Answer

I would like a GameObject to have both a Collider and a Trigger 1 Answer

Drag Player Object using Physics 2D 0 Answers

OnTriggerEnter2D fired by non-trigger 2D collider 0 Answers

Character's trigger collides with itself 2 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