ROLL a ball towards the player

Hi guys, I’m having a bit of trouble trying to get a ball to move towards the player while maintaining a rolling effect. Right now I’m using transform.LookAt which is basically freezing the X and Z rotation of the ball. I’ve tried making a separate object which looks at and moves towards the player and then having a mesh (without the rigidbody and collider) of the ball with a script to follow the separate object but this caused resulted in a very odd effect where the ball just seemed to rotate randomly and move straight in the positive X direction. The second I deleted the ball, the separate object I created works perfectly fine. I’m really lost, any ideas?

I hope you don’t mind C# but I just whipped this up for you to take a look at. I’m not sure if you did actually want to go with rigidbodies for it or not but if you did I hope this can help. You just need to attach it to the ball and set the object of attraction to the player. You can also choose what type of attraction you want it to be, although it’s very basic… I hope I’ve understood your question correctly with this…

As long as your physics materials are set up to have friction (you can set up a default material in the Physics settings) the ball will also roll as it is moving towards the target.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(Rigidbody))]
public class AttractedObject : MonoBehaviour {
	
	[SerializeField] Transform objectOfAttraction;
	[SerializeField] AttractionType attractionType;
	[SerializeField] float attractionStrength;
	[SerializeField] bool useSqrtOfDistance;
    
	Transform myTransform;
	Rigidbody myRigidbody;
	
	void Awake() {
		// cache these
		myTransform = transform;
		myRigidbody = rigidbody;
	}
	
	void FixedUpdate() {
		
		// get the positions of this object and the target
		Vector3 targetPosition = objectOfAttraction.position;
		Vector3 myPosition = myTransform.position;
		
		// work out direction and distance
		Vector3 direction = (targetPosition - myPosition).normalized;
		float distance = Vector3.Magnitude(targetPosition - myPosition);       // you could move this inside the switch to avoid processing it for the Constant case where it's not used
		
		// apply square root to distance if specified to do so in the inspector
		if (useSqrtOfDistance) distance = Mathf.Sqrt(distance);
		
		Vector3 resultingForceAmount = Vector3.zero;
		// depending on which type of attraction, work out the appropriate
		// amount and direction of force to apply to cause movement
		switch (attractionType) {
		case AttractionType.Constant:
			resultingForceAmount = attractionStrength * direction;
			break;
		case AttractionType.DecreaseWithDistance:
			resultingForceAmount = attractionStrength * direction / distance;
			break;
		case AttractionType.IncreaseWithDistance:
			resultingForceAmount = attractionStrength * direction * distance;
			break;
		}
		
		// then finally add the force to the rigidbody
		myRigidbody.AddForce(resultingForceAmount);
		
	}
	
	enum AttractionType {
        DecreaseWithDistance, // (like gravity)
        Constant,             // constant force magnitude
        IncreaseWithDistance  // (opposite of gravity)
	}
	
}