Orbit problem in 5.0 unity

I’m having an issue with the below script not working. The sun and planet are not rotating as they should. I got this code from a tutorial online from a different site. This tutorial was written in 4.0 and I have unity 5.0. I have a feeling something in 5.0 is different and is why it is not working. The planet and sun are both prefabs, don’t know if that makes a difference. I have them a prefabs so later down the road I can click on screen and add planets or suns. I just want to know what I’m doing wrong in the code below. Any help would be greatly appreciated, please let me know if you need anything further.

using UnityEngine;
using System.Collections;

public class Orbiting : MonoBehaviour {

    public Transform Sun;
    public Transform Planet;
    
   // public static 
    //public Rigidbody rb = UnityEngine.Component.GetComponent<Rigidbody>();
    void Awake()
    {
        Rigidbody rb;
        rb = GetComponent<Rigidbody>();
        Planet = transform;
        
        rb.AddForce(transform.forward * 100);
        rb.AddForce(transform.up * 100);
    }
	// Use this for initialization
	void Start () {
        GameObject sun = GameObject.FindGameObjectWithTag("Sun");
        
        Sun = sun.transform;

	}
	
	// Update is called once per frame
	void Update () {
       Rigidbody rb;
        rb = GetComponent<Rigidbody>();
        Vector3 line = Sun.position - Planet.position;
        line.Normalize();
        float distance = Vector3.Distance(Sun.position, Planet.position);
        rb.AddForce(line * 10 / distance);
	}
}

First you should not Initialise your Rigidbody in Update. You already cached it in Awake but in order to use it you need to declare it inside the class and not inside functions like this:

Rigidbody rb;

void Awake()
{
    rb = GetComponent<Rigidbody>();
}

void Update()
{
   //now you can use rb in Update without the need to get the component
}

That being said you won’t have the need to do this because I think you don’t need rigidbody. It was educational only :wink:
Your code is making your planet object moving toward the sun. As I assume you want it to actually orbite around the sun you should first see this: Unity - Scripting API: Transform.RotateAround

It is using Transform and not Rigidbody.

I never used it but my guess would be it’s working like this:

 void Update() 
{
    Planet.RotateAround(Sun.position, Vector3.up, 20 * Time.deltaTime); // you might need to tweak the 20 value for speed
}

As you are moving a transform, if your planet needs a Rigidbody don’t forget to set the flag isKinematic to it.