Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Sep 23, 2017 at 06:28 AM by Ediir for the following reason:

Other

avatar image
0
Question by Ediir · Aug 07, 2017 at 07:27 AM · rotationaccessclamped rotation

Clamp rotation of object - Door

Ive tried to find the answer here, but i was not able solve it myself. First of all, im a novice at coding. Trying out Unity for architecture visualization.

Here is what im trying to achive : I use the FPSController to walk around in the scene. I first made a script for opening doors with keydown and animation, with help from a tutorial. Then i figured i wanted to open doors an other way, so i tried makeing a new script :

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class OpenDoorWithScroll : MonoBehaviour
 {
 
     public UnityStandardAssets.Characters.FirstPerson.FirstPersonController controller;
 
     public float RotationSpeed = 4f;
 
     public float MaxRotation = -90f;
     public float MinRotation = 0f;
   
     void Start()
     {
         
     }
 
     void OnMouseDrag()
     {
 
        float rotY = Input.GetAxis("Mouse X") * RotationSpeed * Mathf.Deg2Rad;
         rotY = (Mathf.Clamp(rotY, -45.0F, 45.0F));
         transform.RotateAround(Vector3.up, -rotY);
 
         Debug.Log(rotY);
     }
 }


The rotation works, but i cant clamp it. So it rotates 360 degrees aroud pivot. The Debug returns low numbers, like : 0.135435 and so on. I would like to clamp it at 90 and 0 as the Variables says, and i would like to add that i have to hold down "E", while dragging, not just drag.

I also want to access the FPSController, to turn off the rotation in the MouseLook script when i start dragging the door open. I figured i could turn off X and Y Sensitivity, but somehow i cant access anything on the FPSController, Except "FPSController.SetActive" when FPScontroller is added as public GameObject. If i dont disable rotation here, the cam turns away from the door while im opening it.

Hopefully someone could give me a hand with this.

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

  • Sort: 
avatar image
0

Answer by HarshadK · Aug 07, 2017 at 08:45 AM

It is a problem due to unit mismatch. Your rotY is a value in radian as you are multiplying your RotationSpeed with Mathf.Deg2Rad and you are trying to clamp the rotation in degrees. So you need to clamp the rotation angle in radian itself. So you can multiply your 45 with Mathf.Deg2Rad or use the value of 45 degrees in radian directly, which is pi/4 (i.e. 0.78539816339). So your clamp statement becomes:

 rotY = (Mathf.Clamp(rotY, -45.0f * Mathf.Deg2Rad, 45.0f * Mathf.Deg2Rad));



Comment
Add comment · Show 2 · 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 Ediir · Aug 08, 2017 at 06:59 AM 0
Share

Thank you, for your answer. It still rotates 360 degrees, it kind of only incrased rotation speed when i drag the door.

It tried changing "-45.0f", with the $$anonymous$$ax and $$anonymous$$inRotation Variables, to see if it had any effect when i tried changing the numbers. If i set one to 0, and the other to 90, it would go fast in one direction without dragging it open, just clicking, and no rotation the other direction.

Thank you agein for your time

avatar image Jack_Veritac · Mar 25 at 08:56 PM 0
Share

Works... kinda. It's not you, it's my code. It's spagetti. :P Thank you for being the only person on this platform to have an answer to this problem! :D

Follow this Question

Answers Answers and Comments

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

Related Questions

Trouble rotating tank cannon. 0 Answers

How to clamp character rotation on Y and X axis? 1 Answer

Clamp rotation value. 0 Answers

How to lerp rotate the gun to the opposite of ur mouses X position and clamp it 1 Answer

Camera clamp angle has issue at inspector angle of 0 degrees 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