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 :wink:

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