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 /
avatar image
0
Question by Rangr · Oct 08, 2015 at 01:38 AM · c#stealthcover

Testing if the player is holding a direction?

I'm working on a third person stealth game. I want include a mechanic in which, if you are snapped to cover, move up to a corner, and continue holding the vague direction of the corner, you will peek around the corner. I have most of this implemented and it should work, I just don't know how to test whether the player is holding a direction or not. I will include my current implementation (although some of it might not make sense without context of the rest of the code). It currently ends in an infinite loop. If anyone has any ideas, that would be amazingly helpful. Thanks!

void PeekCover(int rotDir) { int count = 0; float rotation = Mathf.Round(closest.transform.localEulerAngles.y + closest.transform.parent.transform.localEulerAngles.y); float srotation = Mathf.Round(swapper.transform.localEulerAngles.y + swapper.transform.parent.transform.localEulerAngles.y); bool inCorner = true; Vector3 dirCheck = movement;

         //check if against a wall
         if(rotDir == 1)
         {
             if(srotation == 90)
                 inCorner = false;
         } else if(rotDir == 2)
         {
             if(srotation == 270)
                 inCorner = false;
         } else if(rotDir == 3)
         {
             if(srotation == 180)
                 inCorner = false;
         } else if(rotDir == 4)
         {
             if(srotation == 0)
                 inCorner = false;
         }
         //end wall check
         Debug.Log("hi");
 
         if(inCorner == false)
         {
             if(rotDir == 1)
             {
                 while(dirCheck == movement && count <= 50)
                 {
                     count++;
                     Debug.Log("count");
                 }
                 if(count >= 50)
                     transform.Rotate(30f * Time.deltaTime, 0f, 0f);
                     //rotate x by 30
                 while(dirCheck == movement && count >= 50)
                 {
                     if(Input.GetKeyDown("left ctrl"))
                     {
                         //switch cover to second closest
                     }
                 }
                 if(count >= 50)
                     transform.Rotate(-30f * Time.deltaTime, 0f, 0f);
                 //derotate
             }
             else if(rotDir == 2)
             {
                 while(dirCheck == movement && count <= 50)
                 {
                     count++;
                     Debug.Log(count);
                 }
                 if(count >= 50)
                     transform.Rotate(-30f * Time.deltaTime, 0f, 0f);
                     //rotate x by -30
                 while(dirCheck == movement && count >= 50)
                 {
                     if(Input.GetKeyDown("left ctrl"))
                     {
                         //switch cover to second closest
                     }
                 }
                 if(count >= 50)
                     transform.Rotate(30f * Time.deltaTime, 0f, 0f);
                 //derotate
             }
             else if(rotDir == 3)
             {
                 while(dirCheck == movement && count <= 50)
                 {
                     count++;
                     Debug.Log(count);
                 }
                 if(count >= 50)
                     transform.Rotate(0f, -30f * Time.deltaTime, 0f);
                     //rotate z by -30
                 while(dirCheck == movement && count >= 50)
                 {
                     if(Input.GetKeyDown("left ctrl"))
                     {
                         //switch cover to second closest
                     }
                 }
                 if(count >= 50)
                     transform.Rotate(0f, 30f * Time.deltaTime, 0f);
                 //derotate
             }
             else if(rotDir == 4)
             {
                 while(dirCheck == movement && count <= 50)
                 {
                     count++;
                     Debug.Log(count);
                 }
                 if(count >= 50)
                     transform.Rotate(0f, 30f * Time.deltaTime, 0f);
                     //rotate z by 30
                 while(dirCheck == movement && count >= 50)
                 {
                     if(Input.GetKeyDown("left ctrl"))
                     {
                         //switch cover to second closest
                     }
                 }
                 if(count >= 50)
                     transform.Rotate(0f, -30f * Time.deltaTime, 0f);
                 //derotate
             }
          }
     }
Comment
Add comment · Show 2
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 Xeong-Hu · Oct 08, 2015 at 03:09 AM 0
Share

Hmm, exactly what is it that you need? Please excuse my question, I am having trouble understanding.

But I think what you're looking for is a rotation velocity. or something like that, I came across before but never used it. So like if (this GameObject Rotation Velocity == 0) { Then after that you Start a Coroutine, and count up to how many seconds you want}

Then when Coroutine reaches that limit create a Boolean called Player is Holding Direction.

And bam.

If that's not what you needed then srry about that, I'm not too far off from a beginner myself lol.

avatar image Rangr Xeong-Hu · Oct 11, 2015 at 05:04 AM 0
Share

Well, I could not find anything about rotation velocity in the unity documentation. I'm not entirely sure what you're referring to therefore. I do think that you know what I'm looking for though.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Making a bubble level (not a game but work tool) 1 Answer

Finding closest object to player 3 Answers

An OS design issue: File types associated with their appropriate programs 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