• 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 AnaRhisT · Jun 19, 2010 at 11:03 PM · move

problem occur when moving to the hit.point

*this thread isn't connected in any way to the previous one.

there're 2 problems I encouter : 1. When I move to the hit.point so it moves fast at first, and then gradually slowing its speed when im near the hit.point, i want it to go straight with its speed without slowing or anything - i thought because of yield; but without yield; it won't work :/

When I'm standing on the terrain which its surface's height is really high(like a mountain) and moving to a low height so it like flies to that hit.point and not 'walks' to it..

private var speed = 1; var object : Transform; var hit : RaycastHit;

var movePosition : Vector3; var moving : boolean = false; animation.wrapMode = WrapMode.Loop;

function Update(){ var ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, hit, 3000) && hit.collider.tag == "Terrain" && Input.GetButtonDown("Fire1")) { if(moving) { movePosition = hit.point; }else{ movePosition = hit.point; MoveObjectToString(); } } } function MoveObjectToString() { moving = true; while(Vector3.Distance(movePosition, transform.position) > 0.1){ animation.CrossFade("walk"); var controller : CharacterController = GetComponent(CharacterController); var direction : Vector3 = movePosition - object.position; controller.SimpleMove(direction * speed); yield; } animation.CrossFade("idle"); moving = false; }

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

Answer by Tetrad · Jun 19, 2010 at 11:07 PM

The reason you see the speed problem is because you're not normalizing your direction vector.

Change this line

controller.SimpleMove(direction * speed);

to this:

controller.SimpleMove(direction.normalized * speed);
Comment
Add comment · Show 2 · 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 AnaRhisT · Jun 19, 2010 at 11:11 PM 0
Share

You're so right! now I releaize that what a guy told me really needed to be re-considered about using .normalized.. Thank you Tetrad! 1 problem left now, to make a real move!

avatar image AnaRhisT · Jun 20, 2010 at 08:46 AM 0
Share

Solved. also adding if((CollisionFlags.CollidedBelow) != 0){ is useful.

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

No one has followed this question yet.

Related Questions

how can I move my unity pro or iphone to anyother macbook? 2 Answers

Translate object on y axis 0 Answers

Instantiate VS Transform 1 Answer

Stop Character moving immediately 2 Answers

3d rail shooter rails 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