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 /
This question was closed Jun 16, 2015 at 08:24 PM by DiebeImDunkeln for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DiebeImDunkeln · Jun 15, 2015 at 06:29 PM · flyingtankridgidbody

Flying Tank problem

Hi,

I made a simple tank 3D model and a simple controller script for it:

 public class TankScript : MonoBehaviour {
 
     public float speed = 10.0F;
     public float rotationSpeed = 100.0F;
 
 
     void FixedUpdate() {
 
         float translation = Input.GetAxis("Vertical") * speed *-1;
         float rotation = Input.GetAxis("Horizontal") * rotationSpeed;
         translation *= Time.deltaTime;
         rotation *= Time.deltaTime;
         transform.Translate(translation, 0, 0);
         transform.Rotate(0, rotation, 0);
 
     }
 
     
 }

I gave the tank model a rigidbody and placed the tank on my terrain. My problem is, that the tank is starting to fly if it is driving over a small hill. It jumps and flys a long distance.

I tried to give it a really high mass, but that doesn't help. So, what can I do to avoid that problem?

thanks in advance Frank

Comment
Add comment · Show 7
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 Vice_Versa · Jun 15, 2015 at 06:40 PM 0
Share

this might be a dumb question but is gravity turned on for the rigidbody component?

avatar image DiebeImDunkeln · Jun 15, 2015 at 07:05 PM 0
Share

yes gravity is turned on. the tank is moving on the ground, but if i drive up a small hill it's behavior is like a jetski on a wave.

avatar image Vice_Versa · Jun 15, 2015 at 07:47 PM 0
Share

im not sure, your code looks like it should work but try this change transform.Translate(translation, 0, 0); to transform.Translate(Vector3.Forward * translation, 0, 0);

avatar image Vice_Versa · Jun 15, 2015 at 07:53 PM 0
Share

also, maybe try making the gravity stronger? go to edit > project settings > physics > and make the gravity a bigger number

avatar image DiebeImDunkeln · Jun 15, 2015 at 08:03 PM 0
Share

the gravity default setting is the earth gravity. i think that shouldn't be changed. perhaps it will be better to use .addForce on the ridgidbody ins$$anonymous$$d of transform.translate.

Show more comments

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by RLin · Jun 16, 2015 at 01:15 AM

You should really use rigidbody.addforce on the tank instead of modifying its transform. Anything with a non-kinematic rigidbody doesn't work well with non-instantaneous transform changes. Note that you may have to increase addforce to some pretty high values and then play around with it to get the right speed. Also, your tank will still be able to fly if it's going too fast, but this will be physically realistic.

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 DiebeImDunkeln · Jun 16, 2015 at 06:41 AM 0
Share

I changed now to translate and the behavior seems to be better now, but it's speeding up to much, so I have to check out how to limit the force that I give to the object.

In the first person controller script I saw also that they set .velocity to the object to nail it to the ground?!

avatar image DiebeImDunkeln · Jun 16, 2015 at 11:27 AM 0
Share

I changed now my script completely and get some good result with this:

 using UnityEngine;
 using System.Collections;
 
 public class TankController : $$anonymous$$onoBehaviour {
 
     private Rigidbody rb;
     public float BaseSpeed = 80f;
     public float BaseRotation = 120f;
     public float $$anonymous$$axThrust = 6f;
     public float $$anonymous$$axRotation = 4f;
     private float thrust;
     private float rotation;
 
     // Use this for initialization
     void Start () {
         rb = GetComponent<Rigidbody>();
     }
     
     // Update is called once per frame
     void FixedUpdate () {
 
 
         thrust = Input.GetAxis("Vertical");
         rotation = Input.GetAxis("Horizontal");
 
         if (rb.velocity.magnitude > $$anonymous$$axThrust)
         {
             rb.velocity = rb.velocity.normalized * $$anonymous$$axThrust;
         }
 
         if(rb.angularVelocity.magnitude > $$anonymous$$axRotation)
         {
             rb.angularVelocity = rb.angularVelocity.normalized * $$anonymous$$axRotation;
         }
        
 
         rb.AddForce(transform.forward * BaseSpeed * thrust);
         rb.AddTorque(transform.up * BaseRotation * rotation);
     }
 
     void OnGUI()
     {
         GUI.Label(new Rect(100f, 10f, 500f, 50f), "Speed: " + rb.velocity.magnitude);
 
     }
 }
 
avatar image DiebeImDunkeln · Jun 16, 2015 at 01:17 PM 0
Share

hmm it's damn hard to find the right mass / speed settings. at the moment I have the problem, that the tank tilt if I drive against the smallest hill.

avatar image RLin · Jun 16, 2015 at 02:24 PM 0
Share

$$anonymous$$any vehicles use wheelcolliders or other methods to move rather than addforce.

avatar image DiebeImDunkeln · Jun 16, 2015 at 03:52 PM 0
Share

I think wheelcolliders is the next, what I will test. But I have to modify my tank before that. I never planned to make the wheels turn ^^

Show more comments

Follow this Question

Answers Answers and Comments

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

Related Questions

Animating Tank Treads 0 Answers

fire tank in any direction 1 Answer

How to use 2 Character Controllers in a scene 1 Answer

player on trigger enter dont work? 1 Answer

Movement Issue: x value of object resets automatically 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