copying parent rotation vectors to child vectors

I seem to have the opposite problem of the answers here.
I want to copy the parent rotation vectors or world rotation vector to a child rotation vectors to force the child to follow the parent spin. I know that the child should follow the parent but it does not. The problem is the parent spins but the child does not. I have had this problem awhile now. It is different.

TIA.

public var target : Transform;
public var distance = 10.0;

public var xSpeed = 250.0;
public var ySpeed = 120.0;

public var xMinLimit = -359; //-20;
public var xMaxLimit = 359; //80;
public var yMinLimit = -359; //-20;
public var yMaxLimit = 359; //80;

static public var x = 0.0;
static public var y = 0.0;
static public var xread = 0.0;
static public var yread = 0.0;
static public var xhbase = 5;
static public var xlbase = 5;
static public var yhbase = 5;
static public var ylbase = 5;

static public var xhigh = 5; //window boundaries
static public var xlow = 5;
static public var yhigh = 5;
static public var ylow = 5;


//private var z = 0.0; //mod

@script AddComponentMenu("Camera-Control/Mouse halo")

function Start () {
 //Debug.Log("Made it to Start");
  shotaim_neuter();
	//z = angles.z; // mod

	// Make the rigid body not change rotation
   	if (rigidbody)
		rigidbody.freezeRotation = true;
}

function Update(){
	//if (Input.GetKey(KeyCode.Space)) Debug.Log("space pressed");
	if (Input.GetButtonDown ("Fire3") || Input.GetKey(KeyCode.RightControl)) {
		shotaim_neuter();
		//cuebStatic();
		//CalculateCuebRotation();
	}
}

function cuebStatic(){
//Debug.Log("Made it to cuebStatic");
		x = 0;
		xread = 0;
		xlow = xread - xlbase;
		xhigh = xread + xhbase;

		y = 0;
		yread = 0;
		ylow = yread - ylbase;
		yhigh = yread + yhbase;
		
		var rotation = Quaternion.Euler(0, 0, 0);
        //var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
        
        transform.rotation = rotation;
		}

//var angles : Transform; // pickup mouse angles
	
function shotaim_neuter() {
	// This resets the mouse window of difference of the distance to the saved dynamic center point
	// By creating a new saved x and y center point of the mouse
	// It is not x = 0 or y = 0 !!!!!
	//Debug.Log("Made it to shotaim_neuter");
	//Debug.Log("GameObject.MouseHalo.Mouse neutered");
	//xread += Input.GetAxis("Mouse X") * xSpeed * 0.02;
    //yread += Input.GetAxis("Mouse Y") * ySpeed * 0.02;
	var angles = transform.eulerAngles; // pickup mouse angles
		xread = angles.x;
		xlow = xread - xlbase;
		xhigh = xread + xhbase;

		yread = angles.y;
		ylow = yread - ylbase;
		yhigh = yread + yhbase;
		
}

function LateUpdate () {
//Debug.Log("Made it to LateUpdate");
	CalculateCuebRotation();
}
function CalculateCuebRotation() {
//Debug.Log("Made it to CalculateCuebRotation");
    if (target) {
    
        xread += Input.GetAxis("Mouse X") * xSpeed * 0.02;
        yread += Input.GetAxis("Mouse Y") * ySpeed * 0.02;
		//Debug.Log("New xlow: " + xlow + "  *****  " + "New xhigh: " + xhigh);
		//Debug.Log("New ylow: " + ylow + "  *****  " + "New yhigh: " + yhigh);
		//Debug.Log("Xread: " + xread + "  Yread: " + yread);
		//Debug.Log("X: " + x + "  Y: " + y);
		if (xread < xlow)
			var xlowdiff = (xlow - xread) / 4;
			x = x + xlowdiff;
			//++x;
		//if (x > xhigh) x= xhigh;
		if (xread > xhigh)
			var xhighdiff = (xread - xhigh) /4;
			x = x - xhighdiff;
			//--x;
		//if (x < xlow) x= xlow;
		if (yread < ylow) 
			var ylowdiff = (ylow - yread) / 4;
			y = y + ylowdiff;
			//++y;
		//if (y > yhigh) y= yhigh;
		if (yread > yhigh)
			var yhighdiff = (yread - yhigh) / 4;
			y = y - yhighdiff;
			//--y;
		//if (y < ylow) y= ylow;
		
 	    //z -= Input.GetAxis("Mouse Z") * ySpeed * 0.02; //mod
 		
 		x = ClampAngle(x, xMinLimit, xMaxLimit); //remd out by me
 		y = ClampAngle(y, yMinLimit, yMaxLimit); //remd out by me
 		
 		//**********************************************************************************************
        // Feed x,y with a continual, plus or minus sequential value to rotate
        // When this synchronizes with the mouse saved angles
        // the rotation stops because the mouse to cube difference are zero.
        // As the mouse variance is greater from its dynamic center point(set by middle mouse button)
        // the rotation is faster.
        // Setting tht angle to 0,0,0 will not stop the rotation.
        // The mouse parameters need to be fixated also.
        //**********************************************************************************************
//Debug.Log("x: " + x + "y: " + y);
        var rotation = Quaternion.Euler(y, x, 0);
        //var position = rotation * Vector3(0.0, 0.0, -distance) + target.position;
        
        transform.rotation = rotation;  // Rem this out to freeze
		
	  //transform.position = position;
	  
	  }
}

static function ClampAngle (angle : float, min : float, max : float) {
	if (angle < -360)
		angle += 360;
	if (angle > 360)
		angle -= 360;
	return Mathf.Clamp (angle, min, max);
}

Fixedupdate()
	var opponentdirection = GameObject.Find("Opponents").transform.rotation;
	Debug.Log('Opponents x: ' + opponentdirection.x + ' y: ' + opponentdirection.y + ' z: ' + opponentdirection.z);
	var worlddirection = GameObject.Find("GameObject").transform.rotation;
	Debug.Log('world x: ' + worlddirection.x + ' y: ' + worlddirection.y + ' z: ' + worlddirection.z);

Had used localRotation. This now rotates the child. I need to do the same for rigidbody.

But why?

The easy way is to add in the child's Update() method this line: transform.rotation = transform.parent.rotation; More interesting, however, is why this happens? Can you give a screenshot of your hierarchy, and code snippets of your scripts (if relevant)?

(say "commented out" not "remmed out" if you want more people to understand you)

1 Answer

1

Rigidbodies do not automatically rotate with their parent. If you need to use a Rigidbody, you would need to use a Joint to keep it in some way affected by it’s parent. But it sounds like you do not even need a Rigidbody.

No, a Collider is sufficient for that. But since you're moving them, you'll get better performance with a Kinematic Rigidbody (set Is Kinematic in the Inspector).

So do you want it to "bounce around like rubber balls" or do you want it to follow the parent's rotation? You can't want both.

To clarify, a parent relationship on a Rigidbody does not really do anything beyond the initial position. It does not (and should not) affect the transform of the child with the Rigidbody. To have a relationship between Rigidbodies, you either need to use a Joint or change it with a script.