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 James Ser · Jun 20, 2011 at 07:19 AM · charactercontrollersmootheasing

Easing character controller movement

Hi lovely unity guys again,

I need some help with easing character controller movement. I'm developing an iPad app with a character moving with a finger swipe. Basically, it moves when i wipe my finger across the screen. How do I achieve an easing movement before the character eventually comes to a stop. I've stripped down some of the codes but the character movement is something like this.

 private var character : CharacterController;
 var movement : Vector3 = Vector3.zero;
 
 movement = thisTransform.position - targetLocation;
 movement *= Time.deltaTime;
 character.Move( movement );



I reckon there should be some of a smoothing script? please correct me if i'm wrong.

Thanks guys. Appreciate it.

Rgds, jser


updated code:

 var startspot : Transform;
 var endspot : Transform;
 
 function Start () {
     SmoothMove(startspot.position, endspot.position, 5.0);
 }
 
 function SmoothMove (startpos : Vector3, endpos : Vector3, seconds : float) {
     var t = 0.0;
     while (t <= 1.0) {
         t += Time.deltaTime/seconds;
         transform.position = Vector3.Lerp(startpos, 
                                    endpos, Mathf.SmoothStep(0.0, 1.0, t));
         yield;
     }
 }
Comment
Add comment · Show 8
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 James Ser · Jun 21, 2011 at 12:40 AM 0
Share

Thanks ChrisD for updating my post again.

avatar image James Ser · Jun 21, 2011 at 01:32 PM 0
Share

That's weid, i was trying to edit my question but i couldn't find a save button after i finish typing the changes. And the textbox is full of html tags. Please help. Thanks.

avatar image Marnix · Jun 21, 2011 at 01:34 PM 0
Share

I already updated my answer. You have to use Update() ins$$anonymous$$d of Start(). See my answer.

After editing your question, you need to press the POST ANSWER button again. It's at the bottom of your example view

avatar image James Ser · Jun 21, 2011 at 01:49 PM 0
Share

mmm...this is what i see on my screen when I click on the edit button under my question - http://www.jamesser.com/wip/screenshot.png

I couldn't see any Post Answer button :/

avatar image Marnix · Jun 21, 2011 at 02:01 PM 0
Share

ok that's very odd. You should also see an example window underneath your question, so you can see what you asked.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Marnix · Jun 20, 2011 at 04:50 PM

You are looking for ease in ease out, which is very easy to accomplish. You don't only use Time.deltaTime, but you have to multiply it with a speed. This speed is varying while moving. I found a reference for you, but you could easily look for ease in ease out

  • http://forum.unity3d.com/threads/28312-A-smooth-%28ease-in-amp-out%29-version-of-Lerp

  • http://www.unifycommunity.com/wiki/index.php?title=Mathfx

  • Free in the asset store: iTween. A framework full of this kind of functions.

Update
The biggest problem you're having, is that you call your function only once at Start(). Instead, you should call it everyframe, because else your character only moves a little piece over deltaTime (which is about 0.002 seconds). Try using this in the Update() instead. Here you can read about all overridable methods in a MonoBehaviour.

Comment
Add comment · Show 6 · 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 James Ser · Jun 20, 2011 at 11:53 PM 0
Share

Hi $$anonymous$$arnix, thanks for getting back. I'm trying to use the following code but how do I implement it to my character.$$anonymous$$ove( movement )?

movement is a Vector3 and Smooth$$anonymous$$ove(startspot.position, endspot.position, 5.0) is a co-routine. Thanks again.

[code in post]

ps: And one side question. How do i add a grey background to the codes in my future questions, like how ChrisD help me with.

avatar image Marnix · Jun 21, 2011 at 12:03 AM 0
Share

@James Ser: Indeed, this is barely readable. If you have any updates on your question post them in your question. Every line of code should be preceded with four spaces. Do this easy by selecting your code and pressing the 10010101 button in the editor. If you revise this code in your question, I will have a look at it.

avatar image James Ser · Jun 21, 2011 at 05:34 AM 0
Share

Hi $$anonymous$$arnix, it seems like i can't edit my initial question. I have edited my question as an answer. Pardon me for being dumb and appreciate your assistance. Thanks!

avatar image Marnix · Jun 21, 2011 at 03:21 PM 0
Share

@James Set: This was on the forum that I posted in my question: http://forum.unity3d.com/attachment.php?attachmentid=6564&d=1250101098

avatar image James Ser · Jun 21, 2011 at 03:32 PM 0
Share

Hey $$anonymous$$arnix, thanks for sending that across. How do i use this in conjunction with my character.$$anonymous$$ove( movement ) to give easing effect before my character comes to a stop?

Show more comments

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

CubeWorld's controller 0 Answers

Getting a smooth jump with the Character Controller 3 Answers

Smoothly move with Character Controller 3 Answers

I have a basic character controller script set up, but the problem is that it doesn't run smoothly across the surface of a terrain, usually when there are slopes on the terrain. 0 Answers

animated color: how to smooth? 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