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 black843 · Dec 05, 2014 at 09:10 PM · rigidbodyreference

Refer to a parent Rigidbody

Hey

I would like to make a simple reference to my parent gameobject which has a Rigidbody. All time I would like to hadle with it I suck. Does not rly work at all. I hope you can help me there.

 using System.Collections;
 public class TankMoveBehaviour : MonoBehaviour {
     public Rigidbody daVoda;
     public string daVodaX;
     public Vector3 eulerAngleVelocity = new Vector3(0, 100, 0);
     public bool check = false;
     public bool forward = false;
     public bool backward = false;
     public bool rotateleft = false;
     public bool rotateright = false;
     // Use this for initialization
     void Start () {
     
         daVoda = null;
         //daVodaX = this.gameObject.transform.parent.name.ToString();
     }
     
     // Update is called once per frame
     void Update () {
         //daVodaX = this.gameObject.transform.parent.name.ToString();
         //Debug.Log(this.gameObject.transform.parent.name.ToString());
         if(check == true)
         {
             {
         daVoda = this.gameObject.transform.parent.rigidbody;
                 Debug.Log(daVoda.ToString());
         }
         if(Input.GetKeyDown(KeyCode.F))
         {
             forward = true;
         }
         else
         {
             forward = false;
         }
         if(Input.GetKeyDown(KeyCode.C))
         {
             backward = true;
         }
         else
         {
             backward = false;
         }
         if(Input.GetKeyDown(KeyCode.X))
         {
             rotateleft = true;
         }
         else
         {
             rotateleft = false;
         }
         if(Input.GetKeyDown(KeyCode.V))
         {
             rotateright = true;
         }
         else
         {
             rotateright = false;
         }
         if(forward == true)
         {
             daVoda.AddForce(transform.forward * 200);
         }
         if(backward == true)
         {
             daVoda.AddForce(-transform.forward * 200);
         }
         if(rotateleft == true)
         {
             Quaternion deltaRotatio = Quaternion.Euler(-eulerAngleVelocity * Time.deltaTime);
             daVoda.MoveRotation(rigidbody.rotation * deltaRotatio);
         }
         if(rotateright == true)
         {
             Quaternion deltaRotatio = Quaternion.Euler(-eulerAngleVelocity * Time.deltaTime);
             daVoda.MoveRotation(rigidbody.rotation * deltaRotatio);
         }
         }
     
     }
 }


That's all. I don't know why nothing happens....

Thank's for each answer ;)

Comment
Add comment · Show 1
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 EvilTak · Dec 06, 2014 at 01:54 PM 0
Share

$$anonymous$$ake sure that your object has a parent. If you are 100% sure then there should be no problem. Or if you will be assigning it at runtime, don't forget your trusty null checks!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by M-G-Production · Dec 05, 2014 at 09:52 PM

Hi .black!

Try this! Store the parent in another Transform variable!

 public Transform daVodaParent;
 public Rigidbody daVoda;
 
 void Start()
 {
     //You don't need to set daVoda to null!! Already the case.
 }
 
 void Update()
 {
     //ADD THIS
     daVodaParent = transform.parent;
     daVoda = daVodaParent.rigidbody;
 }

This should work!

Bests, Math

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

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

Related Questions

Using hinge joints to make a balance board 1 Answer

Object Reference Required to access non-static member 'UnityEngine.RigidBody.AddRelativeTorque' 1 Answer

colliders arenot colliding 1 Answer

NullReferenceException Error, has not been solved yet. 3 Answers

Adding a collider to a rigidbody stops addforce working. 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