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 Eco-Editor · Jul 31, 2017 at 03:28 PM · animationcameratransformvreyes

Mathf.Abs and How to play animation only if x,z transform has changed by 0.2 units ?

Hello all,

I'm using HTC VIVE for a multi user game, and there's an avatar that is following the cameraEye component, acting like a third controller person.

I want the walking animation to play if cameraEye is moving and Idle animation to play if cameraEye is Idle. The thing is, cameraEye is never really idle, and its transorm is alway changing a little bit.

I want to say that only if position has changing x+-0.2, z +-0.2, then play animation, else keep idle.

EDIT: I'm trying this code but it's not really working:

     private void Update()
     {
             if ((Mathf.Abs(currentPosition.x) - Mathf.Abs( lastPosition.x) >=0.2f) || (Mathf.Abs(currentPosition.x) - Mathf.Abs(lastPosition.x) <= 0.2f) && (Mathf.Abs(currentPosition.z)- Mathf.Abs(lastPosition.z) >= 0.2f) || (Mathf.Abs(currentPosition.z) - Mathf.Abs(lastPosition.z) <= 0.2f)) 
     {
 
         Vector3 currentPosition = transform.position;
         if (currentPosition != lastPosition)
         {
             playerAnimator.SetBool("Walk", true);
             lastPosition = currentPosition;
         }
         else
         {
             playerAnimator.SetBool("Walk", false);
         }
 
     }


     




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 Eco-Editor · Jul 31, 2017 at 05:06 PM 0
Share

say I have a transform.x

transform.x = idle

but

transform.x+0.2f || tranform.x-0.2f = walk

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Krish-Vikram · Aug 01, 2017 at 10:37 AM

I Think the condition should be as follows..

 if ( Mathf.Abs(currentPosition.x - lastPosition.x) ==0.2f  &&
      Mathf.Abs(currentPosition.z - lastPosition.z) == 0.2f )

P.S: 1. Use && or || according your expected logic. 2. Rounding off the currentPosition, lastPosition might be better if you need exactly 0.2f difference.

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 Eco-Editor · Aug 01, 2017 at 10:56 AM

What I need is if the player moves 0.2 or higher on the x and/or z axis than this indicates he's moving. Else, if the delta is smaller, this means the player didn't really moved, maybe leaned forward and so play idle animation.

Also I do need this entire raw, like that:` if ((Mathf.Abs(currentPosition.x) - Mathf.Abs( lastPosition.x) >=0.2f) || (Mathf.Abs(currentPosition.x) - Mathf.Abs(lastPosition.x) = 0.2f) || (Mathf.Abs(currentPosition.z) - Mathf.Abs(lastPosition.z)

because I want the current and the last positions to be absolute and not just the delta. Otherwise I might get negative number that will sum up to be a very high positive number. @Krish-Vikram Perhaps I'll change the && to be ||.

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

214 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 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 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

"Lerp" back to original position after animation. 0 Answers

how to get eye position and rotation steamvr 2 Answers

GearVR rotation stutter InputTracking.GetNodeStates 1 Answer

Following my camera animation in Vr 0 Answers

Smoothly move camera Field of View upon Trigger 2 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