Conflicing c# scripts

So I have this object that I want a random rotate on a prefab using a script called RandomRotate.

using UnityEngine;
using System.Collections;

public class RandomRotator : MonoBehaviour
{
	public float tumble;
	
	void Start ()
	{
		rigidbody.angularVelocity = Random.insideUnitSphere * tumble; 
	}
}

I also want this Prefab to gravitate towards the center of the game environment and have two scripts to accomplish this. The one attached to the same gameobject that I want to rotate is:

using UnityEngine;
using System.Collections;

public class FauxGravityBody : MonoBehaviour {

	public FauxGravityAttractor attractor;
	private Transform myTransform;

	// Use this for initialization
	void Start () {
		rigidbody.constraints = RigidbodyConstraints.FreezeRotation;
		rigidbody.useGravity = false;
		myTransform = transform;
	
	}
	
	// Update is called once per frame
	void Update () {
		attractor.Attract(myTransform);
	
	}
}

And the other is attached to a null gameobject and the code goes like this:

using UnityEngine;
using System.Collections;

public class FauxGravityAttractor : MonoBehaviour {

	public float gravity = -10;
	public void Attract(Transform body) {
		Vector3 gravityUp =(body.position - transform.position).normalized;
		Vector3 bodyUp = body.up;

		body.rigidbody.AddForce (gravityUp * gravity);

		Quaternion targetRotation = Quaternion.FromToRotation (bodyUp, gravityUp) * body.rotation;
		body.rotation = Quaternion.Slerp (body.rotation, targetRotation, 50 * Time.deltaTime);
	
	}
}

The random rotation only works if I have the FauxGravityBody unchecked. But when it’s on, there is no rotation. I’m a total noob and have no idea what is wrong. Can some one please help? Thanks

[35758-screen+shot+2014-11-22+at+1.23.38+pm.png|35758]

When you use a RigidBody, the RigidBody is meant to take on the transformation of an objects position, this includes rotation unless you have specifically/explicitly frozen the axis(eses).

In one case you’re dorking around with the angularVelocity on Start, thats fine, that happens in a single frame when your RandomRotator script is enabled.

Note: rigidbody.angularVelocity documentation states you shouldn’t dork with this value. However if you are going to, perhaps you should put it in a FixedUpdate() call as you should all physics manipulations, not in Update. Please read the documentation on RigidBody.

In the other case, you have both enabled another script or two to make additional modifications during Update() no less that is called every frame, Start is called on the frame when a script is enabled, so think about it, if it’s called in one frame, lets say your running 30-60 frames per seconds and Update is called EVERY FRAME, you probably won’t even notice what Start has done to the object as the Attach call in your FauxGravityBody script begins modifying the rotation amongst other values as you add force, etc.

Well, your FauxGravityAttractor class sets the rotation so your up vector points upwards in relation to your gravity (line 13 an 14). That of course prevents the rigidbody from rotating since you set the rotation each frame.