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 Inan-Evin · Mar 25, 2015 at 09:37 PM · camerafpscharacterrotateclamp

Clamping the Camera, according to the player ?

Hello everyone, I am trying to achieve a little different kind of a FPS camera. First, my camera is no the child of our player, they are seperated. When my player is standing still, I want to be able to look at the player body freely, without rotating the player. So I wrote my camera script according to that, camera is rotated through X & Y inputs. If the camera looks to right or left with 80~ angle, I want the character body to start rotating. I achieved this, I substract player's euler Y from camera's euler Y, and if that value is bigger than 80, I start rotating the player to the euler Y of the camera. ( I use Mathf.Abs to determine if it's bigger than 80 or not. ) Now the problem comes, If I rotate my camera too fast, player's body can't catch it and camera sometimes sees the back of the body, since there are no restrictions for it. So I need to clamp it, but simply clamping it with -90 & 90 is a huge problem, since camera has no parent object it's world euler y will be clamped and it will be unable to rotate more than -90, 90, according to world. So I need something like this :

 f_InputY = Mathf.Clamp(f_InputY, t_Player.eulerAngles.y - 90, t_Player.eulerAngles.y + 90);

but when I use this, camera seems to jump. Because for example let's say player's euler Y is 0, if I rotate it left, it'll be 359. 359 - 90 = 269. So the camera will be clamped with 90 - 269, which makes it jumps to the 90 directly.(Where it's actually supposed to be in the region of -90, 90) So, any ideas how to implement a system like that ? I tried a lot of different things, like parenting the camera and setting the position & rotation of that parent equal to a reference child object's position & rotation, which is a child of the player. But I could not achieve a smooth controlling. Also some other problems occur when I move the character, because if the player is not standing still, I want the controls to switch to a casual FPS Camera, which X Input rotates the character, and Y Input rotates the camera only. And there are too many ways to achieve rotations, like using AngleAxis, SmoothDampAngle, Quaternion.Lerp, Slerp and more on. I do not know which one is suitable for which way of controlling. If anyone could point me in the right direction or give some guidelines, I'll very happy. Thanks :)

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 Inan-Evin · Mar 26, 2015 at 10:28 PM

Solved the issue, using this reference. It's a perfect guideline for anyone who is having problems about clamping and wrapping an angle.

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

Turning torso of character with mouse 0 Answers

Set Max Rotation On Weapon Sway 0 Answers

Mouselook Is rotating Z-Axis of Camera Unexpectedly 1 Answer

FPS Hands and Arms look way too stretched and weird when looking up or down 1 Answer

Sidescroller Turning 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