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 /
  • Help Room /
avatar image
0
Question by Rookas · Apr 21, 2016 at 11:53 AM · movementcirclecircular

Circular movement for the player

Spent 4 hours trying to implement this so I must be doing something wrong.

I want the player object to be able to move in a circle when a special target locking mode is activated. I'm done implementing mode switching. I also have this method which enforces the circular motion:

 void LockMotionUpdate()
     {
         t += h * Time.deltaTime * 0.05f * speed;
         
         Vector3 d = Vector3.zero;
         d.x = tcenter.x + R * Mathf.Cos(t);
         d.z = tcenter.z + R * Mathf.Sin(t);
         transform.LookAt(tcenter);
 
         transform.position = d;
     }

alt text

This function uses the parametric equation of a circle and it works as expected. h is the parameter, which is received as input from one of the controller axes.

The center of the circle, tcenter, is calculated in another function which is run once upon activating the mode:

 void LockMotion()
     {
         
         R = 4f;
 
         var a1 = transform.forward;
         a1.y = 0f;
         a1.Normalize();
         a1 *= R;
         var a2 = transform.position;
         a2.y = 0f;
 
         //calculate the center of the circle in which the player will be moving
         tcenter = a1 + a2;
     }

The center is expected to be at point which is R units away from the player in the direction it is facing. When activating the mode, I want the player to already be on the circumference, with the center being R units ahead in the facing direction.

The problem is that when I activate this circular motion mode, the code "sees" the player object as the center of the circle and jumps it to some point on the circumference so that it can begin moving in the circle. How do I fix this?

u.png (377.6 kB)
Comment
Add comment · Show 3
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 toromano · Apr 21, 2016 at 12:13 PM 0
Share

What is t's initial value? it looks like it should be 270 degree

avatar image Rookas toromano · Apr 21, 2016 at 01:29 PM 0
Share

The circle in light green is just for illustrative purpose, it does not reflect an in-game situation. But anyway, speed = 50.0f, Time.deltaTime = 0.02f (in my case) and h, being input from an axis, ranges between -1 and 1. So t is around 0.05.

Also, t should not be in degrees, since it's a parameter of the parametric equations, so it should just be some value which, when plugged into the equations, gives points on a circle.

avatar image toromano Rookas · Apr 21, 2016 at 02:16 PM 0
Share

This expression :

  d.x = tcenter.x + R * $$anonymous$$athf.Cos(t);
  d.z = tcenter.z + R * $$anonymous$$athf.Sin(t);

might start your player any place on circle according to your players orientation.

Using transform.RotateAround function might be better:

  void Lock$$anonymous$$otionUpdate()
      {
          float t = h * Time.deltaTime * 0.05f * speed;
           transform.RotateAround (tcenter, Vector3.up, t);
          transform.LookAt(tcenter);
      }

Hope that helps.

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Moving object inside another object's area 1 Answer

2D How to move the prefabs circular upwards? 0 Answers

Movement Script Affecting Other Player's Movement 1 Answer

Circular Movement(Endless Runner) 0 Answers

Parametic equation for circular motion not giving desired effect 0 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