• 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
1
Question by bbergeron · Oct 21, 2012 at 10:20 PM · train

How do I make an object slow down to a stop?

I am currently Trying to make my train go to a stop. The character is on a moving train and I want him to pass a certain point and this will make the train slow down and stop. I currently have a stationary train and a moving background to give the illusion that the train is moving. How can I make the background slowly stop after a certain point? Any suggestions? I assumed a simple for loop would be able to do this but can not figure it out. This is my code for it.

var speed:double; function Start () {

}

function Update () { gameObject.transform.position.x-=speed; } function OnTriggerEnter () { gameObject.transform.position.x-=0; }

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 Fattie · Oct 22, 2012 at 07:44 AM 0
Share

unityGE$$anonymous$$S.com will help

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Hannibalov · Oct 22, 2012 at 08:55 AM

You could use Slerp function: http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Slerp.html

or SmoothDamp

http://docs.unity3d.com/Documentation/ScriptReference/Vector3.SmoothDamp.html

and apply it to your position vector. I would do that in the Update function

Comment
Add comment · Show 5 · 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 bbergeron · Oct 23, 2012 at 11:21 PM 0
Share

How can I use these to help me? I havent been able to use either of these to work

avatar image bbergeron · Oct 23, 2012 at 11:23 PM 0
Share

Slerp make is go in a circle and lerp is only one second long and I need it to be a lot higher than that

avatar image Kiloblargh · Oct 23, 2012 at 11:57 PM 0
Share

"lerp is only one second long"

No, lerp is only Linear Interpolation. It has nothing to do with time, it takes a start value, an end value, and a percentage.

avatar image Hannibalov · Oct 23, 2012 at 11:58 PM 0
Share

You haven't shown much code, but I think this is what you need:

float decelTime = 10; // 10 seconds to decelerate, for example float currentDecelTime = 0; bool decelerating = false; Vector3 speed; //I always think it's best to use Vectors ins$$anonymous$$d of floats.

Update() { if(decelerating){ float interpolatingFactor = currentDecelTime/decelTime; Vector3 move = Vector3.Slerp(speed, Vector3.zero, interpolatingFactor);

transform.position -= move; currentDecelTime += Time.deltaTime; } }

OnTriggerEnter() { currentDecelTime = 0; decelerating = true; }

Translate that into JS or C# and it should be running (I made quite a few syntax errors, but I'm doing this with a tablet and it's not very comfortable)

avatar image sonapax · Mar 21, 2013 at 10:19 PM 0
Share

you $$anonymous$$AN! many thanks +++

void CameraFocus() { if (Left$$anonymous$$ouse_CLIC$$anonymous$$) { focusedObject = GetClickedGameObject(); } if (focusedObject) { Debug.Log("focusedObject:"+focusedObject); if (Left$$anonymous$$ouse_UP) { cameraOBJ.transform.position = Vector3.SmoothDamp(cameraOBJ.transform.position, focusedObject.transform.position, ref velocity, FocusTime);
}

     }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

13 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

Related Questions

Advanced collisions: mesh collision? 0 Answers

Make locomotive Pull Carriage 0 Answers

How do I move my train with a slider, and not W & S 1 Answer

Best way to create a train. 0 Answers

I want to make train simulator. 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