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 /
  • Help Room /
avatar image
0
Question by AwesomeX · Sep 07, 2015 at 06:22 PM · rotationalignmentlooking

4 Directional Looking / Cross positional aiming + Leg alignment?

I'm trying to setup 4 directional looking for my player. Where basically the player can look up, down, left, and right. But if they look past a certain degree either left, or right. The legs and torso realign to the new angle. Similar to how Source games handle their cross positional aiming.

I'm wondering what the best way to do this in Unity would be. Right now I have my mecanim setup with a blend tree, and I have two mecanim Floats "LookAngleX" and "LookAngleY" and that works great.

http://webm.host/eb8df/vid.webm

As the video shows above, it looks just fine when I have the two Floats setup to the camera's X and Y rotations.

 lookAngleX = camera.localRotation.y;
 lookAngleY = camera.localRotation.x;

But I have nothing setup to handle if the Y rotation goes over "for example" a 45 degree angle, to realign the legs and look forward again.

If anyone has done this before, please share how you did it. It would help a lot!

Comment
Add comment · Show 1
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 AwesomeX · Sep 08, 2015 at 12:09 AM 0
Share

So I've been going at this stuff all day, "I'm dying oh god help me"

What I've come to find out is, I have a mecanim blend tree that relies on two floats. - "lookAngleX" and "lookAngleY" for Up, Down, Left, and Right ai$$anonymous$$g/looking.

I have these two floats hooked up to my camera's rotation.

 [code]        [NetSync]
         public float moveX, moveY, velocity, lookAngleX, lookAngleY;
 
         public Vector2 lookPos;
 
         protected override void Update()
         {
             base.Update();
 
             if (IsOwner)
             {
                 //Animator
                 moveX = Input.GetAxis("Horizontal");
                 moveY = Input.GetAxis("Vertical");
                 velocity = controller.velocity.magnitude;
                 lookAngleX = lookPos.y;
                 lookAngleY = lookPos.x;
 
                 //Looking
                 lookPos = new Vector2(camera.rotation.x, camera.rotation.y);
 
                 if (lookAngleX >= 0.4f || lookAngleX <= -0.4f)
                 {
                     print("Angle past 0.4f/-0.4f");
 
                     //model.transform.rotation = Quaternion.Euler(0, camera.eulerAngles.y, 0);
                 }
             }
 
             //Animator
             animator.SetFloat("$$anonymous$$oveX", moveX);
             animator.SetFloat("$$anonymous$$oveY", moveY);
             animator.SetFloat("Velocity", velocity);
             animator.SetFloat("LookAngleX", lookAngleX);
             animator.SetFloat("LookAngleY", lookAngleY);
         }[/code]

So if the camera moves / the player looks around, then so does the floats for mecanim. And it works perfectly when the player is looking forward.

The problem is, when the player's camera rotates, such as 90 degrees. The floats are drastically changed, and possibly inverted. Which completely wrecks my mecanim blend tree, since it depends on a float between -0.4f and 0.4f, or something like that. But since the camera rotated, the float ends up completely different.

I can't quite think straight, but it seems like I need to change how my floats are set with the camera, it seems like it needs to account for the model rotation as well?

I'm terrible at explaining this..

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

29 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

Related Questions

Rotate LOCAL y axis to match Joystick input 0 Answers

Rotating player to look in a fixed direction but on a planet (sphere world) 0 Answers

How to align fps Player to surface normal and use look At on a target 0 Answers

FromToRotation for a die / dice 0 Answers

i am using a code to make my cube walk with character controller ,but when i play the cube spins. 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