Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
4
Question by Hanneswall · Aug 16, 2010 at 06:06 PM · movingwaypointtowards

Moving an object towards hit.point

Hi!

I'm currently making a Dungeon Crawler-type game and I'm having a little bit of trouble with the movement of the character.

The way that it works right now is that I have an waypoint object which is moved around the game world using Raycast.

Moving the waypoint around like this works, moving the character to the waypoint has presented more of a challenge to me though. Looking up earlier answers I've found this script:

var target : Transform; var speed = 5.0;

function Update () {

 transform.position = Vector3.Lerp (
 transform.position, target.position,
 Time.deltaTime* speed);

}

While this script works in a way (it does move the character to the waypoint) it moves the character as if it was connected to the waypoint with a spring and as such moves faster the farther away you put the waypoint.

What I would like is to move the character at a constant speed toward the waypoint. Anyone got any idea how to achieve this?

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
8
Best Answer

Answer by Wolfram · Aug 16, 2010 at 10:57 PM

float distance=Vector3.Distance(transform.position, target.position);
if(distance>0){
    transform.position = Vector3.Lerp (
    transform.position, target.position,
    Time.deltaTime* speed/distance);
}
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 Hanneswall · Aug 17, 2010 at 10:19 AM 0
Share

Thanks a lot, it worked great!

avatar image BlacKatFever · Oct 25, 2011 at 07:53 AM 0
Share

Thanks for this answer! It helped me a lot as well!

avatar image Binxalot · Feb 15, 2013 at 09:52 PM 0
Share

Thank you so much, I've been trying to figure this out for hours now. Found this answer by complete accident.

avatar image easy rhino · Jun 01, 2013 at 01:24 PM 0
Share

Same here - thanks!

avatar image c6y · Dec 12, 2013 at 06:35 AM 0
Share

thanks! @Wolfram

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to stop an object in every waypoint? 1 Answer

Move object A towards object B 2 Answers

Enemy Nudging Towards Player 1 Answer

Moving an Object towards another Moving Object 2 Answers

rotating/moving colliders with or without rigidbodies? 2 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