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 i7Gam3r · Dec 19, 2010 at 10:36 PM · camerarotationfpsfreezerotation

How to restrict a cameras max/min rotation?

Hi!

I have this huge problem of mine, and I can't find any solution to this.. Have tried meny ways but none of them works for me.

I'm still a beginner of unity, but I will learn to use it one step at a time..

Im trying to make a FPScamera myself and The problem is that it turns all the way around when you look up.. So that you eventually end up loooking forward again.. I dont want that. I want the camera to Stop moving "Up" when it has reached the point where it's actually is looking up, at the angle of 90 degrees I think it would be. The same for looking down. So my Code is:

//Simple Cam Move

//Drag player into Player transform

//Set camera as a child of Player

var rotateSensitivity = 5; var Player : Transform;

function Update () { var vertic : float = Input.GetAxis("Mouse Y"); var horiz : float = Input.GetAxis("Mouse X");

if(Input.GetAxis("Mouse Y")){ transform.Rotate(Vector3(-vertic * rotateSensitivity,0,0)); }

if(Input.GetAxis("Mouse X")){ Player.Rotate(Vector3(0,horiz * rotateSensitivity,0)); } }

I had in mind that i could use Mathf.Clamp to restrict it But with no sucsess.. Maby something like this?

 transform.rotation.x = Mathf.Clamp(transform.rotation.x, -10, 10);

Maby im just doin it wrong.. You tell me. Im toaly Stuck on this. Plz Help! Thx! //Edvin

Comment
Add comment · Show 4
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 Eric5h5 · Dec 19, 2010 at 11:02 PM 0
Share

The $$anonymous$$ouseLook script from standard assets already does $$anonymous$$/max clamping.

avatar image i7Gam3r · Dec 20, 2010 at 04:27 PM 0
Share

I dont want to use that,, And i cant figure out how to convert Cs into Js.. as I said i want to make my own $$anonymous$$ouselook.. But I cant figure out how to clamt the rotations...

avatar image i7Gam3r · Dec 20, 2010 at 05:47 PM 0
Share

I$$anonymous$$ GOING CRAZY RIGHT NOW!!!! HOW THE * DO YOU SOLVE THIS!? HAVE SIT HERE FOR HOURS NOW AND CANT FIND EVEN 1 SINGLE SOLUTION!!?? IS IT RLY THAT HARD? //ragemode... Totaly flipping out here!

avatar image Jesse Anders · Dec 20, 2010 at 06:54 PM 0
Share

It's not hard. If you're still having problems with it, I'd recommend starting a thread in the forums (be sure to include your current code and a description of how it's not working).

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Jesse Anders · Dec 19, 2010 at 10:53 PM

Transform.rotation is a unit-length quaternion, so this:

transform.rotation.x = Mathf.Clamp(transform.rotation.x, -10, 10);

Won't do anything useful.

What I would recommend is to create a 'pitch' variable, adjust this variable in response to mouse input, use Mathf.Clamp() to clamp it as desired, and then each update, set the local rotation for the object like this (guessing at UnityScript syntax):

transform.localEulerAngles = Vector3(pitch, 0, 0);
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 i7Gam3r · Dec 20, 2010 at 03:40 PM 0
Share

Thx for the sugestion.. I will try it out.. and if it works properly I'll use it, otherwise I might have another idea to get it to work the way I want :) $$anonymous$$thxbai!

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

Camera not rotate when following player 1 Answer

Can't stop camera from rotating on Z Axis 1 Answer

Rotating Player with Mouse 0 Answers

How does this first person camera script work? 0 Answers

First Person Shooter Help With Cam 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