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 joeee19 · Feb 28, 2013 at 08:19 PM · ioscontrollerlookat

Can you detect the movement of the left and right How can it?

Sorry for my poor English.

Already, I have to move freely in the virtual keyboard players.

I'm locked on in "transform.LookAt(enemy);", Targetting..

 var enemy : Transform ;
 function FixedUpdate () {
 transform.LookAt(enemy);


In this state, I want to detect if the player is moved to the left or right, or has moved to either.

However, as the image is an overhead view.

The reason for this is if you move to the left, because you want to assign in the "mecanim" individual animations that are walking to the left.

alt text alt text

How do you do it can be detected?

.

I is likely to be used to go etc., "Vector3.Dot" try a few times, I'm not sure.

(in the) function FixedUpdate () {

 newpos = thisTransform.forward;
 var Dot = Vector3.Dot(newpos,prevpos);
 Debug.Log("Dot =" + Dot);
 prevpos = thisTransform.forward;
 


image001.jpg (75.7 kB)
image002.jpg (116.6 kB)
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

Answer by robertbu · Feb 28, 2013 at 09:34 PM

Take a look at SignedDotProduct() method in the Math3D script. I've never used it, but here is the comment with the method:

 //This function calculates a signed (+ or - sign instead of being ambiguous) dot product. It is basically used
 //to figure out whether a vector is positioned to the left or right of another vector. The way this is done is
 //by calculating a vector perpendicular to one of the vectors and using that as a reference. This is because
 //the result of a dot product only has signed information when an angle is transitioning between more or less
 //then 90 degrees.


Comment
Add comment · Show 1 · 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 joeee19 · Mar 07, 2013 at 10:41 PM 0
Share

Thanks for the answer! I was able to resolve the following.

 private var prevpos : Vector3 ;
 private var newpos : Vector3 ;
 
 //in the Update()...
     // Animator Left or Right Judge and Input
     if ( name == $$anonymous$$amaeSuriashi )
     {
         // Dot
         newpos = thisTransform.forward;
         var Dot = Vector3.Dot(newpos.normalized,prevpos.normalized);
         //if (Dot <= 0.9999 )        
             var Cross = Vector3.Cross(newpos,prevpos);
         //else
         //    Cross.y = 0;
             
         anim.SetFloat("Direction",Cross.normalized.y);
         //Debug.Log("Cross = " + Cross.normalized.y);
     }    
 
 function LateUpdate ()
 {
     prevpos = thisTransform.forward;
 }
 

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Script working for standard FPS controller not mobile FPS controller 1 Answer

LookAt not working, points in wrong direction. 1 Answer

Performance Question on Kinematic Rigidbodies 1 Answer

How use Streaming Assets and Handheld.PlayFullScreenMovie iOS? 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