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
1
Question by kishan93 · Feb 02, 2016 at 03:50 PM · movementrotation axiswaypointssmooth follow

I Want My Character To move On Specific Line With Script

alt text I have Plane And Curvy Turn. currently I am Moving my Character Forward by 1 unity every second. now when character comes across "this Curvy Turn" I want it to be rotated 90' on the Y axis but slowly and gradually. and on the plane there are 3 lines on which character can walk (like in the android games "subway surfer" or "Sonic Dash" ).

i have collider to detect entry and exit alt text

Can It Be done using WayPoints or something? just give me some hint.

thanks.

unityqustion01.jpg (28.9 kB)
unityqustion02.jpg (33.0 kB)
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 BigHandInSky · Feb 02, 2016 at 05:33 PM

You have a couple of options based on how accurate you want to be, but both will rely on using some form of loop to go through them:

  1. Have a list/array of transform points,

  2. Using a for loop, foreach point, until you reach the Count/Length of the block -

  3. Move your player transform to the next point, and when (player.transform.position - array[loop].position).magnitude is less than a range you choose, increment the for loop

  4. Continue until you have reached the end.

In code this translates to:

 float nextPointRange = 5.0f;
 Transform[] curveWaypointsArray;
 Transform playerTransform;
 
 // An IEnumerator makes this easier to start when needed,
 // And also allows a greater degree of control over the movement
 IEnumerator MoveThroughArray()
 {
      int loop = 0;
      while(loop < curveWaypointsArray.Length)
      {
           //for simplicity just make the player face the next point each frame
           playerTransform.LookAt(curveWaypointsArray[loop].position);
 
            //while the player is not close to the next position, move forward
            while((curveWaypointsArray[loop].position - playerTransform.position).magnitude > nextPointRange)
           {
                playerTransform.Translate(playerTransform.forward);
                yield return new WaitForEndOfFrame();
           }
           //this makes each run of the while loop last a frame
           yield return new WaitForEndOfFrame();
      }
 
 }
 

Now you can implement this in an update, but it will be a bit more scrappy than an IEnumerator like the one above, which will make doing this far easier to implement, so take an hour/two to read up on them. Hope this helps.

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 kishan93 · Feb 03, 2016 at 03:08 PM 0
Share

Yes, the "LookAt" function helped me. i am using it with virtual WayPoint, i don't really create wayPoints. i am calculating WayPoints, then using LookAt function to rotate my character accordingly.

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

How do I rotate my object back to the world's up direction whilst keeping it's forward direction? 0 Answers

Rotate Object Axis On Swipe Cam Rotation - Android 1 Answer

Player Rotation Around Mouse 0 Answers

moving an object continuously between waypoints 0 Answers

How can I make my GameObject rotate this way? 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