Black Hole Physics...

This forum is currently in read-only mode.
From the Asset Store
A simple fun and stylish endless scroller game ready to be customized and published.
  • 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:

    ->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]http://www.mediafire.com/file/xp3xr875059678k/Black%20Hole.cap[/url]
    
    P.S. My apologies to R0J0hound for stealing his ship sprite... I was just using it for testing. Gonna change it soon!!
  • Might take a look at hinges.

  • 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.

  • yea, your gonna wanna incorporate division to create your falloff, so that it actually fades but has constant effect.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

    Wow.

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

    Thanks!!

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)