How to repel a ball ... Need math help, calling all gurus!

beefy_clyrobeefy_clyro Member Posts: 5,394
edited November -1 in Working with GS (Mac)
Hi Guys. Im struggling to get my head round around a problem and wonder if any of you lovely people can help?

I have a ball shot across the screen to where the player selects. The ball is always launched at the same speed. The ball has a change velocity at 400. What i want it to do is when it goes close to another actor it gets repelled away at its relevant angle, but also the closer the ball is to the actor the greater the repelled force is. So, if you fire within say 100 of the repel actor, it gets repelled just a little, if you shot at say 30 away from the actor then it takes a greater effect.

I can achieve the distances using magnitude, thats fine, i just really dont know what to do about the repel behaviour!

Cheers

Comments

  • RedlerTechRedlerTech Member Posts: 1,583
    It may be simple if you do it right. If actor is this far away, change the self restitution to X
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Afraid this wont work, the ball does not actually collide with the actor! When it gets really close, the force pushing the ball away will be quicker than the ball accelerating towards it, thus pushing it back the way it came. If its in the radius but far away, it will just alter its path slightly
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Hmm I have some ideas I'll see if I can make a demo. I'm low on my demo quota This months. LOL
    email me if I don't get back to you soon. tenrdrmer(at)yahoo.com
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Haha spot on matey, you'll be a god in my eyes if you can nail this one :)

    Cheers
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Haha spot on matey, you'll be a god in my eyes if you can nail this one :)

    Cheers
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Well just an update i've got something together I think I have your email so i'll send it over in just a bit.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    you need to constrain two game attirbutes to the flying ball's x an y. For the repelling actor you'll need to create two attributes (1 real, 1 angle). Then you'll need this in the repelling actor:

    Constrain game.distancefromball to magnitude(game.ballX-self.positionX,game.ballY-self.positionY)
    constrain game.angle to ball to VectorToAngle(game.ballX-self.positionX,game.ballY-self.positionY)

    now you will always have the angle between the two and the distance between the two.

    Just add an accelerate to the ball and use the magnitude data as part of an equation (have a number divided by game.distancefromball) and use game.angle for the angle relative to scene.
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    Thanks guys :) Your help is greatly appreciated.

    Tenrdrmer has sent me a demo which was very kind of him and also thanks to Sci Tunes who was minutes behind posting a solution.

    Man i love this community :D
Sign In or Register to comment.