• 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
Question by jjon126 · Oct 30, 2016 at 07:22 PM · positionmathrotation axis

Character follows a circular rotation around centre with distance, but loops with 360 turn and can't figure out how to move to a certin point

To set the scene I have my player rotating around a centre pivot. You swipe on the mobile device and it will shoot a raycast to hit the object. The player will then move along a cylinder shape towards that position. So imagine the platform the player moves on is a cylinder. The character moves up and down on the Y axis and rotates around the cylinder.

Enemy's spawn on this cylinder with a 0 - 360 placement on it. The player moves on the cylinder from positions 0 to - infinity or + infinity. I sorted it out so the players rotation resets to 0 after it passes 360, same if it passed 0 to 360. Makes it easier to read the position of the player.

The bit I can't wrap my head around is how I can tell if the enemy hit is to the left or the right..

It is easy enough to say if the value is lower than what the current position of the player is then move on the - rotation, same if it positive on the + position. This works fine if it is between 360 to 0 but not if its crossing over from 355 to 5, it should only be 10 degrees away, not 350.

EXAMPLE

The player is on +2 and the enemy is on +355, if I swipe to the left it will go all the way around the cylinder to the right. If i script it so it moves the other way. The same issue will happen if the player is on +355 and the enemy is on +2, it will go the long way around.

The script I am using to move the character around is:

 //Updates variable position
 rot -= .1f * Time.deltaTime;
 //sets and updates the character position
             transform.position = origin + Quaternion.Euler(0, rot, 0) * new Vector3(0, 0, distance);

I hope I have worded that well enough for you to understand...

I added a really bad picture to help with setting the scene. :) alt text

help-1.jpg (50.7 kB)
Comment

People who like this

0 Show 0
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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

80 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

Related Questions

Advanced placing position from the same angle of target position 0 Answers

Object with fixed position but follows camera rotation 0 Answers

How to find a position's angle around an arbitrary axis? 1 Answer

How to properly make an object follow the edge of another object? 0 Answers

Can you help me make an algorithm out of these parameters? 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