Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 icybergenome · Jul 19, 2017 at 04:55 PM · splinesteeringtransformation

How to create a circular motion for an object moving in curved path?

Hi,

I have curved path on which my player is steering through a spline nodes (using cat mull equation). Front face of path is circular and I want my player to make a circular motion on a particular keystroke. For my game scene I have aligned my game objects in following manner:

  • Spline Nodes

  • Player Mover which follows spline nodes and steer through a path (Parent)

  • Player (Child of Player Mover)

  • Camera(Child of Player and Grand child of Player Mover)

I managed to create a circular motion for a player using sin/cos equation for circle. But when circular motion starts, my player looses its contact with the transformation updates provided by parent object(player mover). It only follows the transformation along z axis and player even starts to phase out of the path when the path became curve.

Please suggest a solution. Thanks in advance.

Using following code to make a circular motion:

 speed = (Mathf.PI * 2) / timeToCompleteCircle;
         float x;
         float y;
         switch (direction) {
         case "left":
             currentAngle += Time.deltaTime * speed;
             x = radius * Mathf.Cos (currentAngle);
             y = radius * Mathf.Sin (currentAngle);
             transform.position = new Vector3 (x, y, transform.position.z);
             break;

 









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
1
Best Answer

Answer by Bunny83 · Jul 19, 2017 at 05:00 PM

Do not use the "position " property as it sets the worldspace position of the object. Just use transform.localPosition instead.

 transform.localPosition = new Vector3 (x, y, 0);
Comment
Add comment · Show 2 · 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 icybergenome · Jul 19, 2017 at 05:31 PM 0
Share

Thanks mate! Its working, it means transform.position is for world space?

avatar image Bunny83 icybergenome · Jul 19, 2017 at 05:57 PM 1
Share

Yes, transform.position is the objects position in worldspace. When reading that property Unity actually calculates the worldspace position based on the parent's local space and the objects local position. localPosition actually defines the objects location within the local space of the parent object. If an object doesn't have any parent, localPosition and position are the same.

ps: When you assign a Vector3 to transform.position, Unity actually transforms that position into the local space of the parent and set the localPosition. The localPosition is what you see in the inspector when you select an object.

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

68 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

Related Questions

vehicle decceleration and angle reseting 1 Answer

Setting up Unity Steer 0 Answers

(ideas, resources) RTS AI create its own waypoints without pathfinder 1 Answer

How to make a steering wheel that rotates when wheels do? 0 Answers

Spline Controller (javascript) error 2 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