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 oliver-jones · Feb 13, 2012 at 02:33 AM · collidertransform.positionaxisboundary

Camera Movement Bounds?

Hello,

I have a simple camera movement script that moves on the X,Z axis (the camera is top down). I want to make the camera move within a bounds.

I first tried adding a physical collider around the border and on the camera, but the effect is kind of awful, meaning the camera just bounces off and rotates... It doesn't work basically.

I tried scripted a boundary too by doing this:

 if(transform.position.z < 20){
     transform.Translate(0, Input.GetAxis ("Vertical") * sensitivity, 0);
 }

If the camera moves further than 20, it stops on the Vertical axis like it should, but then I can't move it back down because its out of the if statement.

Any ideas? I sure would appetite it.

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
Best Answer

Answer by Datael · Feb 13, 2012 at 08:53 AM

I'm a little confused that you're checking the z position of the transform but then translating along Y... Is this just a mistake when you re-typed it over here?

Anyway this should be what you're looking for. I'm assuming C#... Either way this should help you get the idea.

 // define max position
 float maxZ = 20.0f; // you could even make this serialized so you can change it from the inspector later

 // figure out how much we are trying to move by
 float wantMoveZ = Input.GetAxis ("Vertical") * sensitivity;
 // make sure we're not going too far
 float moveZ = Mathf.Min(maxZ - transform.position.z, wantMoveZ);

 // finally apply the movement (if there is any)
 if (moveZ != 0) {
     transform.Translate(0, 0, moveZ);
 }

There's more easy ways to do this but I was hoping to keep it a little optimized...

This will keep the movement pinned at a max of 20. If there is no movement in Z then it will not translate the transform, etc, if for some reason it manages to go past 20 it will be reset to 20 (thanks to the min) etc etc

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Using a collider to define the boundary of a level? 3 Answers

How to get the Z - Axis of the Cam 3 Answers

Add a force to a ball using the Boxcolliders AXIS 2 Answers

Script works with hard coded values but not variables 2 Answers

Rotatearound Collider axis 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