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 iuhfewkjbwekj · Mar 11, 2014 at 10:40 PM · cameraclamp

simple clamp camera translate on Y axis only

I have a script for my camera on my player so that the camera can move up and down on the y axis. I don't want the camera to move left and right because my player already rotates left and right on the x axis and the camera follows because it is the players child. Now the problem is that the camera rotates too far up or too far down which is why I need a clamp or bonds for it. I have looked all over Google and other sites but I can not find anything the fits what I'm looking for. All I need is a clamp on the y axis when input axis horizontal is pushed but I also want the camera to follow the player when it moves up and down. Thanks for your help, here's my script.

 private var player : Transform;
 private var speed : float = 10;
 
 function Update() {
     player = GameObject.Find("Gabriel Health Bar Red").transform;
     transform.LookAt(player);
     var translation = Input.GetAxis ("Mouse Y") * speed;
     translation *= Time.deltaTime;
     transform.Translate (0, translation, 0);
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jagster · Mar 11, 2014 at 10:54 PM

not sure if this is 100% what you wanted but the code will lock the camera movement along the axis you chose, just put it in a script and attach that to the camera

 // Update is called once per frame
 void Update () {
     transform.position = new Vector2 (0, transform.position.y);
 }    


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 iuhfewkjbwekj · Mar 12, 2014 at 05:30 AM 0
Share

That's close but not quite. Let me reword it so it makes more since. On the script "mouse orbit", I want that same clamp to be exactly like that but for the y axis only. The script I showed you is just me trying to make a script similar to mouse orbit but, without the ability to move the camera left and right. I tried to edit the script "mouse orbit" to fit what I'm looking for but with my limited amount of experience I could not figure it out. SO what you could do is take the "mouse orbit" script and take out the input axis "$$anonymous$$ouse X." I would do this myself but, like I said I don't know how too and make it still work right. Thanks!

avatar image
0

Answer by iuhfewkjbwekj · Mar 19, 2014 at 12:51 AM

Never mind I figured it out but thanks! private var player : Transform; private var speed : float = 10;

  function Update() {
     player = GameObject.Find("Gabriel Health Bar Red").transform;
     transform.LookAt(player);
     var translation = Input.GetAxis ("Mouse Y") * speed;
     translation *= Time.deltaTime;
     transform.Translate (0, translation, 0, Space.World);
     if (Vector3.Distance(transform.position, player.position) > 8) {
         transform.position += transform.TransformDirection (Vector3.fwd);
     }
     if (Vector3.Distance(transform.position, player.position) < 6) {
         transform.position -= transform.TransformDirection (Vector3.fwd);
     }
 }
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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Clamp Mouse Zoom using Scroll Wheel (SOLVED) 2 Answers

How do I use mathf.clamp to make boundaries for a camera 0 Answers

Bizzare problem with limiting camera veritcal rotation 2 Answers

I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 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