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 SuperProgrammer · Jul 21, 2012 at 02:51 PM · cameramouserotatelimit

Multiple rotate with mouse

If mouse moves upper/lower. Camera will rotate upper and lower between limits. For example: local rotation between Vector3(+45, 0, 0) and Vector3(-40, 0, 0) If mouse moves right/left. Parent object of camera will rotate right/left around Y. For example local rotation Vector3(0, 173, 0) or anything else. In there no limit. Also always mouse will stay at center. I am using c#. you can answer in javascript too, not much problem.

(Edit: Forget to say turrent have a maksimum rotation speed for example: 60 degree per sec so turrent cant rotate too fast also idk how to adapt it)

alt text

graphicofquestion.jpg (26.3 kB)
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
Best Answer

Answer by SuperProgrammer · Jul 22, 2012 at 10:02 AM

Thanks for help

I added final coding:

First i added a variable stores current X rotation because X rotation of camera changes between 320(-40) to 45, 5f is sensitivity, -40 and 45 are limits. Req -Input.GetAxis("Mouse Y") (negative) for if mouse moves upper, came will too else doing opposite

private float CameraXRotation = 0f;
void Update () {
  CameraXRotation = Mathf.Clamp(CameraXRotation - Input.GetAxis("Mouse Y") * 5f, -40f, 45f);
  transform.localEulerAngles = new Vector3(CameraXRotation, 0, 0);
}
similar code for turret (not req a variable for store Y rotation)

transform.parent.localEulerAngles = new Vector3(0, Mathf.Min(transform.parent.localEulerAngles.y + Input.GetAxis("Mouse X") * 5f, Time.deltaTime * MaxTurretRotationSpeed), 0);
And for lock mouse at center of screen + hidden cursor

Screen.lockCursor = true;
for unlock set it to false.

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

Answer by ScroodgeM · Jul 21, 2012 at 08:20 PM

http://docs.unity3d.com/Documentation/ScriptReference/Input.GetAxis.html

just read

Input.GetAxis("Mouse Y")
in camera's control script and apply to locally declared property of float. then clamp it to -40...45 and apply to rotation as
transform.rotation = Quaternion.Euler(new Vector3(val, 0f, 0f));

separately from previous script just read

Input.GetAxis("Mouse X")
in turret's control script and make
transform.Rotate(0, Mathf.Min(val * mouseSensitivity, Time.deltaTime * rotationMaxSpeed), 0);
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

Camera Rotate to mouse position -2 Answers

Camera rotate with mouse in TPC 0 Answers

Scripting Issue With Top Down Mouse Movement 1 Answer

Need to rotate a 3rd person object to the camera rotation 1 Answer

Camera in fixed position which rotates with player. 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