r/KerbalSpaceProgram • DRAMA MAN • Feb 16 '14

Weekly Misc Posts Thread

Anything you want to post that's not directly related to KSP, post it here! (Stuff like launches, space related news, rocket designs etc.)

Popular posts (not including news)

posted by reddit-poster

15 Upvotes

7 comments sorted by

View all comments

Show parent comment

1

u/a1_K_Man Feb 16 '14

This is pretty cool, if you want objects to "wrap around" Asteroids style, toss in these lines during the position update (lines 102 or 103)

        if (each.position[0] <= 0):
            each.position = ((WIDTH - 1.0) , each.position[1])
            each.velocity = ((each.velocity[0]*0.8) , each.velocity[1])
            
        if (each.position[0] >= WIDTH):
            each.position = ((1.0) , each.position[1])
            each.velocity = ((each.velocity[0]*0.8) , each.velocity[1])
            
        if (each.position[1] <= 0):
            each.position = (each.position[0] , (HEIGHT - 1.0))
            each.velocity = (each.velocity[0] , (each.velocity[1]*0.8))
            
        if (each.position[1] >= HEIGHT):
            each.position = (each.position[0] , (1.0))
            each.velocity = (each.velocity[0] , (each.velocity[1]*0.8))

I set their speed to reduce by 20% each loop, though.