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 Coverttrickster · Apr 25, 2016 at 06:22 AM · rotation detection

How would i track rotational direction from my rotation cordinates?

So I am trying to figure out the best way to track whether my camera is moving left, right, left diagonal down, left diagonal up, right diagonal down, right diagonal up, up, and down so I can animate my sword to the correct attack the direction asks for. Currently my code looks like this -

 if(checkXPos > currentPos.x + moveBoundry && checkYPos > currentPos.y + moveBoundry)
 {
         //Left Diagonal Downwards
 }
 else if(checkXPos > currentPos.x + moveBoundry && checkYPos < currentPos.y - moveBoundry)
 {
             //Left Diagonal Upwards
 }
 else if(checkXPos < currentPos.x - moveBoundry && checkYPos > currentPos.y + moveBoundry)
 {
         //Right Diagonal Downwards
 }
 else if(checkXPos < currentPos.x - moveBoundry && checkYPos < currentPos.y - moveBoundry)
 {
             //Right Diagonal Upwards
 }
 else if(checkXPos > currentPos.x && (checkYPos > currentPos.y + moveBoundry || checkYPos < currentPos.y - moveBoundry))
 {
         slashLeft = true;
 }
 else if(checkXPos < currentPos.x && (checkYPos > currentPos.y + moveBoundry || checkYPos < currentPos.y - moveBoundry))
 {
         slashRight = true;
 }
 else if(checkYPos > currentPos.y && (checkXPos > currentPos.x + moveBoundry || checkXPos < currentPos.x - moveBoundry))
 {
         //Down Slash
 }
 else if(checkYPos < currentPos.y && (checkXPos > currentPos.x + moveBoundry || checkXPos < currentPos.x - moveBoundry))
 {
         //Up Slash
 }
 else
 {
         CancelAnim();
 }

So it already tracks my movement distance and my coordinate point that I'm looking at from one point to the another to make a line and I have check points to tell whether I am moving left or right, up or down from the difference of the two updating coordinates. How should I go at this and if there is a better method please by all means let me know thank you.

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 Scribe · Apr 25, 2016 at 10:50 AM 0
Share

by 'camera moving' do you mean 'camera rotating'? $$anonymous$$y thinking is, if your camera is rotating (or moving in fact) that is usually controlled by something the users has already done, like moving the mouse up/down/diagonally, or pressing some combination of keys, so it would make more sense to calculate the motion performed from the source input. Rather than getting the input, using it to move something, then measuring how it moved in order to perform some action, you can skip the middle two steps.

avatar image Coverttrickster Scribe · Apr 25, 2016 at 10:53 PM 0
Share

Yeah I'm recording the cameras rotation x and y values with three different variables. One that records from a start position, one that records where my rotation is currently at, and one that updates to my current rotation after checking the difference of current rotation and the check rotation.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ben-rasooli · Apr 25, 2016 at 02:50 PM

No a better method, but you can clean up your code a bit, it's too confusing! You can nest your conditions to remove some duplication. For example:

 bool movingLeft = checkXPos > currentPos.x + moveBoundry;
 bool movingDown = checkYPos > currentPos.y + moveBoundry;
 bool movingUp = checkYPos < currentPos.y - moveBoundry;
 bool movingRight = checkXPos < currentPos.x - moveBoundry;
 
 if(movingLeft){
     if (movingDown) {
         //Left Diagonal Downwards
     } else if (movingUp) {
         //Left Diagonal Upwards
     } else {
         //Left
     }
 } else if (movingRight) {
     if (movingDown) {
         //Right Diagonal Downwards
     } else if (movingUp) {
         //Right Diagonal Upwards
     } else {
         //Right
     }
 } else if (movingDown){
     //Down
 } else if (movingUp){
     //Up
 }

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 Coverttrickster · Apr 25, 2016 at 10:49 PM 0
Share

I like that! Thanks.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Float value = gameobject.rotation 2 Answers

How can I make player rotation control camera's x rotation and mouse control it's y rotation? 1 Answer

Getting the rotation of raycast target object and applying to the player (noob question) 1 Answer

Align a vector3 with parent's up-vector. 2 Answers

angular velocity only on one axis 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