x


How do I make a planet get sucked into a blackhole ?

I am trying to get a gameobject (planet) to orbit another gameobject (blackhole) in gradually smaller orbits until the planet collides with the blackhole.

This is my current code:

var BlackHoleCenter : Transform;

function FixedUpdate(){

    transform.RotateAround (BlackHoleCenter.transform.position, Vector3(1, 0, 0), 200 * Time.deltaTime);
    transform.LookAt(BlackHoleCenter);
    rigidbody.AddForce(transform.forward*50);
}

If I comment out the transform.RotateAround line, the planet approaches the blackhole gradually as desired, but if I allow the transform.RotateAround line to run, the planet orbits, but never approaches the blackhole.

Why is this?

more ▼

asked Mar 18 '11 at 02:41 AM

Ecnalyr gravatar image

Ecnalyr
159 14 15 26

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

You mixed direct movement(RotateAround) with physic driven movement(AddForce). I recommend to use just direct movement, because you specify all values and the movement isn't really physic based.

var BlackHoleCenter : Transform;

function FixedUpdate(){

    transform.RotateAround (BlackHoleCenter.transform.position, Vector3(1, 0, 0), 200 * Time.deltaTime);
    transform.LookAt(BlackHoleCenter);
    transform.Translate(Vector3.forward*50*Time.deltaTime);
}

You may need to adjust your "50" because it's no longer a force, it's a speed now.

more ▼

answered Mar 18 '11 at 03:03 AM

Bunny83 gravatar image

Bunny83
67.2k 22 69 269

Wow, thank you.

Mar 18 '11 at 03:43 AM Ecnalyr
(comments are locked)
10|3000 characters needed characters left

You could also use physics for it by using:

var BlackHoleCenter : Transform;

function FixedUpdate()
{
    transform.LookAt(BlackHoleCenter);
    rigidbody.AddForce(transform.forward*50);
    rigidbody.AddForce(transform.right*50);

}

This will make the rigidbody be purely physics based meaning you can alter its trajectory during gameplay using other obects/forces.

more ▼

answered Jul 24 '13 at 10:22 AM

Grim_Darknight gravatar image

Grim_Darknight
116 1 4

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2717
x1888
x445
x405

asked: Mar 18 '11 at 02:41 AM

Seen: 1690 times

Last Updated: Jul 24 '13 at 10:22 AM