# How do I create a blackhole effect?

Get help using Construct 2

### » Thu Mar 12, 2015 8:36 pm

I'm creating an asteroid game. I want to have a blackhole in the center. It sucks everything. And the closer an object to the center of the blackhole, the harder it is to get away.
B
10
S
5
Posts: 220
Reputation: 1,464

### » Thu Mar 12, 2015 10:33 pm

easily done.

your objects speed must be calculated. let's say your object has speed 20.
20- e^-koef if koef =0 then e^- koef = 1 if koef > 0 then e^-koef is <1 and if koef <0 then e^-koef > 1
so if koef = 1 speed is 20 - e^-koef = 20 - 1/2.73 if koef =2 then 20 - 1/(2.72)^2 - almost no speed loss.
if koef = -1 then speed is 20 - 2.72, koef = -2 20-2.72^2 and so on.
now if you think about it- koef could be distance. and distance between 2 points is calculated like this:
http://www.mathwarehouse.com/algebra/di ... /index.php (check formula)

you could use foreach object visible on screen - calculate koef and apply speed formula.
and now for the "sucktion" part - you would have to give objects angle towards the object (Black hole). you could do that by giving it 2 speeds. let's say - bullet for movement, and custom for sucktion. - set angle towards black hole, and speed e^-koef , and use bullet for nomal movement (speed 20). so you would have all the time 20 - e^-koef.

i think that would work

there might be though a simpler (or already completed) solution, but i have no idea if there is one.
Sea Monsters template - Isometric
Also includes 40 pages PDF of optimizations and "how-to" for your games, and how the "sea monsters" template was built. Follow link for details :)

sea-monsters-templates-and-assets_t162705
B
41
S
14
G
12
Posts: 623
Reputation: 9,359

### » Thu Mar 12, 2015 10:44 pm

maybe...Apply force toward(BlackHole.Y,BlackHole.Y) ?...
B
63
S
23
G
7
Posts: 1,480
Reputation: 10,796

### » Thu Mar 12, 2015 11:03 pm

Here is a quick and dirty capx of an asteroid getting pulled into a blackhole. It may not be the best way, but its a start for you to modify to your needs.

It uses Rexrainbow's gravitation plugin. Get it Here: https://www.scirra.com/forum/behavior-gravitation-for-physics-behavior_t70521?&hilit=gravitation+plugin

Read up on this for checking the distance between multiple instances of the same object. It has some useful information here as well.

https://www.scirra.com/forum/check-distance-between-2-instances_t65816

Hope this helps.
You do not have the required permissions to view the files attached to this post.
B
9
S
2
Posts: 80
Reputation: 854