Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
This question was closed Jul 08, 2015 at 05:45 AM by DiebeImDunkeln for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DiebeImDunkeln · Jul 05, 2015 at 11:17 AM · terrainridgidbodyclicktomove

click and move vihicle on terrain

Hi,

I have a tank game and want to make the controll for mobile like a click on the terrain and move the tank there. The tank has 3 axes and Wheelcolliders.

I already tried several things but allways run in the problem with different terrain heights. As long as the terrain is flat it is no problem to move the tank, but if there is a small or then the tank get's a strange behavior.

     IEnumerator MoveToPosition()
     {
 
         yield return null;
         while(Vector3.Distance(transform.position, target) > 3 ) {
 
             if(Vector3.Distance(transform.position, target)>3)
             {
                 transform.LookAt(target); 
                 Debug.Log (Vector3.Distance(transform.position, target));
             }
 
             rb.MovePosition(transform.position + transform.forward * 10 * Time.deltaTime);
 
             yield return null;
         }
         MoveToTarget= false;
         yield return null;
     
 
     }

tank

Comment
Add comment · Show 10
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 McGravity · Jul 05, 2015 at 11:40 AM 0
Share

What do you mean by "strange beahviour"? How is your "target" variable filled with a position? What does $$anonymous$$ovePosition do exactly? If rb is a rigidbody like your tag implies you should use forces ins$$anonymous$$d of changing the position directly. Why do you return null at the beginning of the method? You should read the api documentation of components you use carfully. $$anonymous$$ost components have a little questionmark at the top right. Click it.

avatar image DiebeImDunkeln · Jul 06, 2015 at 06:02 AM 0
Share

the strange behavior is that the tank don't use the physics anymore, it's not rotating in the vertical axis if the tank drives a hill. After the click it makes a look at to the target and then don't changes the rotation anymore.

the return null if a relict of a further testing.

I get the target position with a raycast and a hit.point.

avatar image LaneFox · Jul 06, 2015 at 12:10 PM 0
Share

$$anonymous$$ovePosition is simply not a good approach for what you are trying to do. Have you thought about using Nav$$anonymous$$esh, AddForce, or a more robust wheel system to drive the tank ins$$anonymous$$d?

avatar image DiebeImDunkeln · Jul 06, 2015 at 12:12 PM 0
Share

I already tried a navmesh, but it also had to problem with the tank rotations. I think I will try it with addForce.

avatar image LaneFox · Jul 06, 2015 at 12:22 PM 0
Share

Have you enabled any of the constraints on the tank's Rigidbody?

Show more comments

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by n1gth · Jul 07, 2015 at 06:38 AM

Try making putting the NavMeshAgent on the parent object, and the model of the tank in the child object. Then use the NavMeshAgent to drive the tank, and in the Update method of the child, rotate the tank to match the terrain.

See this thread for more discussion and sample code.

Comment
Add comment · Show 3 · 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 DiebeImDunkeln · Jul 07, 2015 at 06:43 AM 0
Share

I had not so much luck with adding force. I will try the Nav$$anonymous$$eshAgent script from your link. thanks.

avatar image DiebeImDunkeln · Jul 07, 2015 at 05:13 PM 0
Share

ok I tried the script of your link and it works like charm for me. Thank you.

avatar image n1gth · Jul 07, 2015 at 05:50 PM 0
Share

Good to hear.

Follow this Question

Answers Answers and Comments

23 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Create a terrain prefab? Saving a terrain? No? 1 Answer

Terrain trees 1 Answer

Generate 16bit terrain map from real world elevation data 3 Answers

Array index is out of range? 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