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 Chris1012 · Apr 14, 2018 at 07:58 PM · 3dplayer movementtrackingfast

How to tell if an object is moving in a circle?

I'm working on a 3D game as a hobby and have been having a lot of trouble figuring out how I would do this.

The player character can run super fast. I want them to be able to run in a circle a couple times and have it simulate a tornado, but I can't figure out how to track if the player is moving in a circle.

I'm not the best with geometry. Is there some sort of algorithm or formula to see if one object has been moving in a circlular motion based on a handful of points? I was thinking maybe something like you would see in a phone game where you can drag your finger in a circle, except it would be a gameobject.

Please help.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by BastianUrbach · Apr 14, 2018 at 09:51 PM

First of all, we need to consider always at least four points at the same time (since one two or three points always lie on some circle). So lets take four consecutive points and test if they lie on a circle. This is quite simple if the speed of the player (and thereby the distance between the points) is constant. In that case you just need to check if the angle (p1, p2, p3) is the same as (p2, p3, p4). Or in code:

bool wasCircular = Mathf.Abs(Vector3.SignedAngle(p1 - p2, p3 - p2, Vector3.up) - Vector3.SignedAngle(p2 - p3, p4 - p3, Vector3.up)) < threshold;
Repeating this for multiple groups of four points should give fairly reliable results. So for example you would do this for (p1, p2, p3 p4) then (p2, p3, p4, p5) then (p3, p4, p5, p6) and so on.

If the speed was not constant it gets a bit more difficult. One approach would be determining a center based on three points and then testing if the distance to that center remained constant and if some angle around the center has been covered with the sign of that angle remaining the same (otherwise we would also detect circular motion if the player is standing still or switched direction).

One thing to keep in mind is that every four points we test should have been sampled at regular intervals that are long enough that some meaningful angle should have been covered (e.g. 30°). Otherwise we would have to set the threshold extremely low to avoid detecting a straight line as circular motion and a low threshold would mean the circle has to be near perfect, which is unlikely to happen.

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 drv14 · Apr 14, 2018 at 08:14 PM

You could divide your screen into quadrants with a collider taking up each quadrant, then see if the player hits the colliders in order.

You could modify the colliders into a flat torus shape or something to avoid shenanigans at the center.

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

86 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

Related Questions

Pyramid 3d moel Please help 1 Answer

Physics based player controller problems 1 Answer

Rotation of player based on camera direction and joystick direction in 3D world 1 Answer

How to turn a corner and have the camera and player keep going in direction the corner is leading to. 0 Answers

How to launch the player into the direction its facing - 3D 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