Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 DevsGoingViral · Jan 08, 2017 at 06:22 PM · javascriptscripting problempositionquaternionparenting

Scripted tank track bones behave strange

Rigged and scripted Tank track mesh and bones behave strange when tank rotating. Actually bones are problem.I'm using existing script i found on internet and slightly edited it. I'm 3D designer but i'm doing my best with little time i can spare to be better at scripting but these are moments where i just stuck. As more as i rotate whole tank,more they "skew". :/ Setup of wheels is basically standard what we will expect,Unity wheels component,meshes following wheels component y position and bones following wheels meshes position. Since game is for mobile i reduced number of wheels which leaves gap in between wheels which gives trouble on short tall obstacles where track mesh will cut into this obstacle so to avoid that i added wheels there also just to support realistic obstacle crossing.I have track and bones following perfectly wheel meshes on y position but everything else is not so great.Basically i have few players playing my old wartank game from one year ago and i appreciate them so i'm truing to give them nice update. Scene setup and code is real mess and i will highly appreciate if someone have will to help me. Tanktrack video from my fb profile < you can see it on video. Here are some images alt text

Here is script:

 #pragma strict
 import UnityEngine;
 import System.Collections;
 
 public var wheelcolliders :WheelCollider[] = new WheelCollider[10];
 public var WheelMeshTransform :Transform[] = new Transform[10];
 var MaximumTorque : float;
 var leftInput : float;
 var rightInput : float;
 var Brakes : float;
 public var pos : Vector3;
 public var quar : Quaternion;
 
 public var Lbone2 : Transform;
 public var Lbone3 : Transform;
 public var Lbone4 : Transform;
 public var Rbone2 : Transform;
 public var Rbone3 : Transform;
 public var Rbone4 : Transform;
 
 public var LhalfBone_a : Transform;
 public var LhalfBone_b : Transform;
 public var LhalfWheelCol_a : WheelCollider;
 public var LhalfWheelCol_b : WheelCollider;
 
 function Start () {
 
 }
 
 function Update () {
 MaximumTorque = 100;
 leftInput = 0;
 rightInput = 0;
 Brakes = 0;
 
 
         if(Input.GetKey(KeyCode.LeftShift) == true){
            leftInput = 1f;
         }
         if(Input.GetKey(KeyCode.LeftControl) == true){
            leftInput = -1f;
         }        
         if(Input.GetKey(KeyCode.RightShift) == true){
            rightInput = 1f;
         }
         if(Input.GetKey(KeyCode.RightControl) == true){
            rightInput = -1f;
         }
         if (Input.GetKey(KeyCode.Space) == true){
             Brakes = 300;
         }
         if(Input.GetKey(KeyCode.LeftShift) == true && Input.GetKey(KeyCode.RightControl) == true){
         MaximumTorque = 150;
         }
         if(Input.GetKey(KeyCode.RightShift) == true && Input.GetKey(KeyCode.LeftControl) == true){
         MaximumTorque = 150;
         }
         
         //Left tread
         wheelcolliders[0].motorTorque = MaximumTorque * leftInput;
         wheelcolliders[1].motorTorque = MaximumTorque * leftInput;
         wheelcolliders[3].motorTorque = MaximumTorque * leftInput;
         wheelcolliders[4].motorTorque = MaximumTorque * leftInput;
         wheelcolliders[5].motorTorque = MaximumTorque * rightInput;
         //Right tread
         wheelcolliders[6].motorTorque = MaximumTorque * rightInput;
         wheelcolliders[7].motorTorque = MaximumTorque * rightInput;
         wheelcolliders[8].motorTorque = MaximumTorque * rightInput;
         wheelcolliders[9].motorTorque = MaximumTorque * rightInput;
         //Meshes Left
         wheelcolliders[1].GetWorldPose(pos,quar);
         WheelMeshTransform[1].position.y = pos.y;
         WheelMeshTransform[1].rotation = quar;
         WheelMeshTransform[1].position.z = pos.z; //fixing wheel position error
         WheelMeshTransform[1].position.x = pos.x; //fixing wheel position error
         
         wheelcolliders[2].GetWorldPose(pos,quar);
         WheelMeshTransform[2].position.y = pos.y;
         WheelMeshTransform[2].rotation = quar;
         WheelMeshTransform[2].position.z = pos.z; //fixing wheel position error
         WheelMeshTransform[2].position.x = pos.x; //fixing wheel position error
         
         wheelcolliders[3].GetWorldPose(pos,quar);
         WheelMeshTransform[3].position.y = pos.y;
         WheelMeshTransform[3].rotation = quar;
         WheelMeshTransform[3].position.z = pos.z; //fixing wheel position error
         WheelMeshTransform[3].position.x = pos.x; //fixing wheel position error
         //faking left wheel rotation
         WheelMeshTransform[4].rotation = WheelMeshTransform[1].rotation;
         WheelMeshTransform[0].rotation = WheelMeshTransform[1].rotation;
         //Half colliders_bones left
         LhalfWheelCol_a.GetWorldPose(pos,quar);
         LhalfBone_a.position.y = pos.y-0.13;
         LhalfWheelCol_b.GetWorldPose(pos,quar);
         LhalfBone_b.position.y = pos.y-0.13;
 
 
         //Meshes Right
         wheelcolliders[6].GetWorldPose(pos,quar);
         WheelMeshTransform[6].position = pos;
         WheelMeshTransform[6].rotation = quar;
         wheelcolliders[7].GetWorldPose(pos,quar);
         WheelMeshTransform[7].position = pos;
         WheelMeshTransform[7].rotation = quar;
         wheelcolliders[8].GetWorldPose(pos,quar);
         WheelMeshTransform[8].position = pos;
         WheelMeshTransform[8].rotation = quar;
         //faking right wheel rotation
         WheelMeshTransform[5].rotation = WheelMeshTransform[8].rotation;
         WheelMeshTransform[9].rotation = WheelMeshTransform[8].rotation;
         
         //Bones left
         Lbone2.position.y = WheelMeshTransform[1].position.y-0.2;
         Lbone2.position.x = WheelMeshTransform[1].position.x;
         Lbone3.position.y = WheelMeshTransform[2].position.y-0.2;
         Lbone3.position.x = WheelMeshTransform[2].position.x; //empty boneFixer.x
         Lbone4.position.y = WheelMeshTransform[3].position.y-0.2;
         Lbone4.position.x = WheelMeshTransform[3].position.x;
         
         
         //Bones right 
         Rbone2.position.y = WheelMeshTransform[6].position.y-0.2;
         Rbone3.position.y = WheelMeshTransform[7].position.y-0.2;
         Rbone4.position.y = WheelMeshTransform[8].position.y-0.2;
 
 
         for(var WC:WheelCollider in wheelcolliders)
         {
             WC.brakeTorque = Brakes;
         }
 
 
 }

trackproblem2.png (424.2 kB)
trackproblem11.png (459.6 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Quaternion.TransformPoint? 1 Answer

Weird delay on Tween 1 Answer

Transform.position can't be changed smoothly. 2 Answers

Transform vector to other coordinate frame using quaternions 1 Answer

how to script a position 1 Answer


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