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 demion90 · Oct 02, 2014 at 12:41 PM · rotationmovement3dmath

Click to move

I need to make realistic human movement (3D) using mouse click.

  1. Get mouse click point using Raycast.

  2. Smoothly Slerp to LookRotation.

  3. Move transform.forward.

Everything works fine, except I have problem with circular movement (close radius).

  1. Example If dont move transform.forward while Slerp to LookRotation or MoveTowards instead of transform.forward it will be spinning like whirligig on circular movement.

  2. Example If do move transform.forward while while Slerp to LookRotation it will distort trajectory of straight direct movement.

Is there any solution to move circular realistic (not spin like whirligig) and move straight direct when needed (not distort trajectory)?

I need straight movement from first example and circular movement from second.

         if (Input.GetMouseButtonDown(1))
         {
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
             RaycastHit[] hits = Physics.RaycastAll(ray);
 
             foreach (RaycastHit hit in hits)
             {
                 if (hit.transform.tag == "Ground")
                 {
                     DestinationPosition = new Vector3(hit.point.x, transform.position.y, hit.point.z);
 
                     DestinationRotation = Quaternion.LookRotation(DestinationPosition - transform.position);
 
                     break;
                 }
             }
         }
 
         if (Vector3.Distance(transform.position, DestinationPosition) > 1)
         {
             transform.rotation = Quaternion.Slerp(transform.rotation, DestinationRotation, RotationSpeed * Time.deltaTime);
 
             transform.position += transform.forward * MovementSpeed * Time.deltaTime;
 
             //transform.position = Vector3.MoveTowards(transform.position, DestinationPosition, MovementSpeed * Time.deltaTime);
 
             animation.CrossFade("run");
         }
         else
         {
             animation.CrossFade("idle");
         }


Comment
Add comment · Show 2
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 Baste · Oct 03, 2014 at 04:23 PM 0
Share

Have you looked at the Unity navmesh system? That would probably be a lot easier than trying to code the same thing yourself, which is what you're doing.

avatar image BLF-Games · Oct 03, 2014 at 07:08 PM 0
Share

What do you mean circular realistic?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by BenKurdziel · Oct 04, 2014 at 05:37 AM

My suggestion for any click to move would be to look at Unity's navmesh system. From a performance standpoint, it's the most optimized and one of the easiest approaches.

If you'd like to look into this, here's some reference material and a quick set up I wrote in about 2 minutes. Good luck!

http://docs.unity3d.com/ScriptReference/NavMesh.html

1) "Window/Navigation"

2) Mark Objects you've clicked on that you'd like people to walked on as "Navigation Static"

3) Bake it when you're done.

4) Put a NavMeshAgent on anything you'd like to move.

5) Call: .SetDestination(hit.point);

Comment
Add comment · 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

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

Rotate towards movement direction 1 Answer

How to calculate xSpeed and ySpeed according to float value of rotation? 1 Answer

Third Person Controller Rotation 0 Answers

How to make an object rotate to raycast hit from mouse? Unity 3D 1 Answer

2D Simulated Sword Swing - Sword Floating Away 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