# Black Hole Physics...

### » Fri Dec 10, 2010 8:34 pm

To train myself in Construct, I am trying to put together a very simple Space War type game...

I have made a Black Hole object (a box!) at the center of my test playfield using the ADD FORCE TOWARDS action. Perhaps my math is wrong, but the following:

[code:19jjef0x]->Sprite: Add force 300-distance(Sprite.X,Sprite.Y, Box.X, Box.Y) towards (Box.X, Box.Y)[/code:19jjef0x]

Will actually repulse the player instead of attract them when the player is on the outskirts of the playfield... I guess because the "300-distance" equation turns up a negative number? Is there a simple way to calculate for that?

Also this method produces very linear results... The force pulling the ship in should become exponentially greater as you get closer to the center of the black hole. That way you can fly around on the outskirts of the playfield with no pull towards the center at all. But if you get too close, you'll get caught in the black hole and sucked in.

Is this the right way to do this kind of thing in Construct?

As an alternate, I made a new version where the force is not applied unless the player sprite overlaps another large CIRCLE sprite I've added to the center of the playfield. Adding a few of these give the desired slight pull, then much greater pull that I'm looking for -- but I can't help thinking this is the wrong way to go about this, and that there is a simple (i.e. MATH) way of handling all this.

Any suggestions..? Current "Double Circle Overlap" version can be found here:
[url:19jjef0x]http://www.mediafire.com/file/xp3xr875059678k/Black%20Hole.cap[/url:19jjef0x]

P.S. My apologies to R0J0hound for stealing his ship sprite... I was just using it for testing. Gonna change it soon!!
B
4
S
1
G
2
Posts: 64
Reputation: 980

### » Fri Dec 10, 2010 9:02 pm

Might take a look at hinges.
B
163
S
48
G
100
Posts: 7,462
Reputation: 72,046

### » Fri Dec 10, 2010 9:55 pm

Try add force (1000000/distance^2) (off the top of my head), and just keep playing around with the formula. At 1000 distance the ship only gets 1 pull force. at 100 distance it gets 100 pull force. You can also use clamp(300-distance,0,300) to make your formula return 0 instead of a negative number.
B
25
S
3
G
6
Posts: 1,198
Reputation: 5,622

### » Fri Dec 10, 2010 10:59 pm

yea, your gonna wanna incorporate division to create your falloff, so that it actually fades but has constant effect.
B
54
S
7
G
6
Posts: 1,949
Reputation: 7,668

### » Sat Dec 11, 2010 12:23 am

[quote="Davioware":4x165uap]Try add force (1000000/distance^2) (off the top of my head), and just keep playing around with the formula. At 1000 distance the ship only gets 1 pull force. at 100 distance it gets 100 pull force. You can also use clamp(300-distance,0,300) to make your formula return 0 instead of a negative number.[/quote:4x165uap]

Wow.
That's pretty perfect for off the top of your head. Works like a charm with those exact numbers!

Thanks!!
B
4
S
1
G
2
Posts: 64
Reputation: 980

### » Sun Dec 12, 2010 11:57 pm

Might want to check for distance bigger than zero before you hit that formula.

Unless you want to see an actual black hole, of course
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665