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 blackmethod · Feb 28, 2013 at 02:52 PM · sizelimitviewportrectangle

Limit the available stage space?

I know the title does me no justice, but I'm working on making a side scrolling space shooter game (sure everyone knows the kind). And I was wondering whats the best way to go about locking the ships movement to a set rectangle that's the same as the viewport, how would you guys do this?

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 Mikilo · Feb 28, 2013 at 03:06 PM 0
Share

Hi, I'm not a pro with camera coords convertion, but you just need to know the distance between the camera and the "space", get the rect and clamp the position consequently.

avatar image MD_Reptile · Feb 28, 2013 at 03:40 PM 0
Share

something along the lines of getting the extents of the screens view, and then comparing the world position of the ship, to the position at the edge (maybe some padding too) and if the players ship passes too far, limit him there at the edge...

so like... screen.width and screen.height will be helping.. and then using camera.main.screenpointtoworldpoint or whatever might help you out as well.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tomtom789 · Feb 28, 2013 at 04:15 PM

Or You Simply make some Cubes around your scene and make them not visible with colliders. ;)

Comment
Add comment · Show 6 · 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 Mikilo · Feb 28, 2013 at 04:25 PM 0
Share

It is a bit heavy for this purpose.

avatar image tomtom789 · Feb 28, 2013 at 04:36 PM 0
Share

If your object is attached to your camera you can just check the positions: Exemple:

 void    Update()
 {
     if (this.transform.position.x > 15.0f) // left
         this.transform.position.x = new Vector3(15.0f, this.transform.position.y, this.transform.position.z);
     if (this.transform.position.x < -15.0f) // Right
         this.transform.position.x = new Vector3(-15.0f, this.transform.position.y, this.transform.position.z);
     if (this.transform.position.y < 15.0f) // Up
         this.transform.position.y = new Vector3(this.transform.position.x, 15.0f, this.transform.position.z);
     if (this.transform.position.y < -15.0f) // Down
         this.transform.position.y = new Vector3(this.transform.position.x, -15.0f, this.transform.position.z);
 }

Or a thing like this. And this work only if your objet is attached to your camera.

Hope it helps. ;)

avatar image MD_Reptile · Feb 28, 2013 at 05:02 PM 1
Share

That couldn't work well in various screen sizes, but if you only use one exact size that would be ok. I still think getting screen extents, then converting either world coordinates to screen coordinates or vice versa would be best for any screen size.

avatar image blackmethod · Mar 01, 2013 at 02:54 PM 0
Share

Thanks for the quick responses guys! I already tried the cube idea but the collision isn't always clean at the speeds my ship gets up to! But I'll definitely give some of these a try, thanks a ton!

avatar image Mikilo · Mar 01, 2013 at 03:08 PM 1
Share

Use cubes as border is not really efficient. Put your elements in camera's children, that's a funny trick.

Show more comments

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

13 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

Related Questions

How to extend tree size to more than 200? 0 Answers

Limit the size/capacity of a list 3 Answers

Unity 2D: Size of a sprite proportional to the size of the viewport? 0 Answers

Limit WWW.texture file size? 1 Answer

Easy way to determine which camera is clicked on? 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