Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 erfan · Jul 05, 2013 at 11:38 AM · rotationtransformailerpwaypoint

object pauses at the each way points for a vary short time

I write this code.

 var waypoint:Transform [];
 internal var  currentWay : int=0;
 var TransformSpeed:float;
 var duration:float;
 var RotationSpeed:float;
 function Start () {
     
 
 }
 
 function Update () {
     
     var target:Transform =waypoint[currentWay];
     transform.rotation=Quaternion.Slerp(
     this.transform.rotation,target.rotation,Time.smoothDeltaTime*RotationSpeed);
     transform.position=Vector3.Slerp(
     transform.position,target.position,
     Time.smoothDeltaTime*TransformSpeed);
     
  }
  
 function OnTriggerEnter (other : Collider) {
     currentWay++;
       
 }

I have an array of way points: "waypoint[]". so my car when trigger each waypoint go the next way point. but something odd will happen . the speed of my car isn't fixed. and each time reach to the waypoint . it is vary slow or even I think stop, and then go vary fast. exactly like our heart Pulse. " fast->normal->vary slow->fast->...." in the other word it is not Continuously , like a real car.

I don't know but I think it is related to the lerp function. can you help me?

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
0

Answer by Seregon · Jul 05, 2013 at 12:28 PM

A lerp/slerp function will move your car a fraction of the distance between two points, in this case its current position and its next waypoint. As your car gets closer to each waypoint, that distance gets smaller, so the fraction of that distance that it moves each update is also smaller, and it moves slower. To get a fixed speed, you can can specify a fixed speed, and divide that by the distance left to the next waypoint to get the fraction (t) you need to move this update, something like the example below. Also, you should be using Vector3.Lerp, not .Slerp, as slerp is intended for use with cartesion rotations, not positions.

 function Update () {
  
    var target:Transform =waypoint[currentWay];
    transform.rotation=Quaternion.Slerp(this.transform.rotation,
       target.rotation,Time.smoothDeltaTime*RotationSpeed);
 
    var distanceToWayPoint = (target.position - transform.position).magnitude;
    transform.position=Vector3.Slerp(
       transform.position,target.position,
       Time.smoothDeltaTime*(TransformSpeed / distanceToWayPoint));
  
 }
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 erfan · Jul 05, 2013 at 04:02 PM 0
Share

Thank you. That is exactly what I want. in The overall , is it a good way to implement the simple 2d top down Ai car? is there any better way?

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

16 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

Related Questions

Rotate a set amount over time WITHOUT lerping 0 Answers

How do you smoothly transition/Lerp into a new rotation? 3 Answers

transform.localRotation lerp precision 1 Answer

Unit rotation fails consistently on all slerp rotations after the first? 0 Answers

How to rotate 90 degrees from 270 degrees to 0 with lerp? c# 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