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 Jakabob247 · Jun 22, 2016 at 05:10 AM · rotationpathfindingpathpathfollowingpaths

My "Smooth Rotation" Jerks around randomly when switching between points.

My character rotation likes to jerk to the right every time it switches points!

What I want is to get my car to constantly move between a set of points smoothly and at a consistent speed. It moves between the points correctly, but the rotation changes to an odd point everytime.

It always rotates a little up and a little to the right every time it switches points. I would like my answer in C# please. While I could probably convert code from Javascript to C#, I hate Javascript, so I never use it. Here is my code:

using UnityEngine; using System.Collections;

 public class ParentMovement : MonoBehaviour {
 
     [SerializeField]
     private Transform[] points;
     [SerializeField]
     private float speed;
     [SerializeField]
     private float rotationSpeed;
 
     private int i = 0;
     
 
     // Update is called once per frame
     void Update ()
     {
         float step = speed * Time.deltaTime;
         if (i < points.Length)
         {
             //Rigidbody GET IT
             Rigidbody rb = GetComponent<Rigidbody>();
             //Move the location to the transform.position.
             transform.position = Vector3.MoveTowards(transform.position, points[i].position, step);
             //Smoothly look to the other object
             Vector3 direction = (points[i].position - transform.position);
             Quaternion lookRotation = Quaternion.LookRotation(direction);
             //Actually LOOK
             transform.rotation = Quaternion.Slerp(transform.rotation, lookRotation, Time.deltaTime * rotationSpeed);
             //Change the points.
             if(transform.position == points[i].position)
             {
                 i++;
             }
         }
     }
 }


Comment
Add comment · Show 1
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 insominx · Jun 22, 2016 at 11:54 PM 0
Share

Watch out for comparing floating point values as you are doing here:

 if(transform.position == points[i].position)

They're unlikely to match most of the time. To start, try changing the points based on when you're close enough. This has one of the more simple explanations out there: dotnetperls

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

How do I get my patrolling enemies to go back to the patrol point they had not gotten to because they chased the player? 1 Answer

i want to make a path system like in racing in gtav,i want to make a path system like racing in gta 0 Answers

Path system or Predetermined paths for Camera Fly-throughs / Ladder climbing / etc 1 Answer

Need to change direction of transform? 2 Answers

A* Pathfinding, destroying a path once it has reached its end 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