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 tapina · Apr 28, 2011 at 09:16 AM · camera2d-platformerlerpz

need help with camera

first of all im quite beginner at this.

okay so the problem is this:

im trying to make 2d game, 2 players, both at the end of the platform shooting each other with cannons. the idea is to have a camera i can move in this field by holding down right mousebutton.

been viewing the lerpz code for the base of the game (camera scrolling and so on) and i made and invisible cube object to "move" the camera.

i attached and self-written fairly easy (too easy?) piece of code to move my invisible cube wich simply uses transform.translate to move my cube while getmousebutton1 is true (i'd paste the code but i just modified it after a small break in on the project and i can't remember the original code how dumb of me)

with that code the invisible cube just keeps going and going if you move your mouse over the level borders, the camera stays inside the borders but the "camera control cube" just keeps going farther and farther away.

any idea how to get the cube stay inside level boundaries?

at the moment im using camera scrolling and focus for my camera and level attributes script for my platform from lerpz tutorial.

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
2

Answer by Tommy · Apr 28, 2011 at 09:23 AM

Im not quite sure, but this might get ju started atleast:

var maxValue = 0; var minValue = 0;

function Update () { if (transform.position.x >= maxValue) { transform.position.x = maxValue; } else if (transform.position.x <= minValue) { transform.position.x = minValue; } }

Also, change the maxValue and minValue to whatever suits.

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

No one has followed this question yet.

Related Questions

Cinemachine Confiner 2D shift my camera view 0 Answers

How to destroy a projectile when it leaves any side of the camera view on a 2D game? 1 Answer

Lerpz 2D Tutorial - Can't Save Scene And Proceed 0 Answers

How to make the camera move up and down the horizontal axis only when the 2D character get's above and below the top half of the screen. 0 Answers

Camera Problem 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