Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / pool table problem

Author
Message
haliop_New
User Banned
Posted: 9th Apr 2016 12:46
hello I'm building a small 2d physics game a pool game.

but something isn't right about it...
when I hit the balls with a stick
they start the physics rutine where the balls are flying across the table but then stuck to the table edges instead of bouncing back from it...

physicsGravity is set to 0,0
physicsScale is set to 0.02
and stepphysics inside the loop is 1
I managed to hit the white ball with a stick , once the stick hits the white ball it pushes it out of the table so there wont be any interfering with the table or other balls
so only the white ball is hitting the other balls...

table edge code : (4 of those that build the table itself)

// top
Ents[currentEnt].id = CreateSprite(0)
SetSpriteSize(Ents[CurrentEnt].id,Size,Size/200)
SetSpritePositionByOffset(Ents[CurrentEnt].id,x,y-Size*1.5/2)
SetSpritePhysicsOn(Ents[CurrentEnt].id,1)
SetSpriteGroup(ents[CurrentEnt].id,-1)
SetSpritePhysicsRestitution(ents[CurrentEnt].id,1)


ball code


function CreateBall(x as float,y as float,size as float,colR as integer,colG as integer,colB as integer)
inc CurrentBall
Balls[CurrentBall].id = CreateSprite(BallHollowImg)
SetSpriteSize(Balls[CurrentBall].id,size,size)
SetSpritePositionByOffset(balls[currentball].id,x,y)
SetSpriteColor(balls[CurrentBall].id,ColR,ColG,ColB,255)
SetSpriteShape(balls[currentball].id,1)
SetSpritePhysicsOn(Balls[CurrentBall].id,2)
SetSpriteAngle(balls[CurrentBall].id,random(0,360))
SetSpritePhysicsMass(balls[CurrentBall].id,size/25)
//SetSpritePhysicsFriction(balls[currentBall].id,1)
SetSpritePhysicsRestitution(balls[currentBall].id,0.25)

endfunction


haliop_New
User Banned
Posted: 9th Apr 2016 12:56
full code
I imagined some people could look at it and learn
hopefully a knight will come to a rescue

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Apr 2016 13:52
Firstly, comment out StepPhysics. Only use this if you want to do something that is abnormal. The Sync() will correctly step the physics for you.

After that you will need to reduce the ball masses, increase the impact, or a combination of both.
Mess around with Friction, restitution, damping and angular damping to get the effect you want.

I have always needed trial and error to get it right. I put all the physics values in a parameter file so they are easy to adjust.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
haliop_New
User Banned
Posted: 9th Apr 2016 14:12
Got it , Thank you BatVink.

Login to post a reply

Server time is: 2024-11-25 08:23:16
Your offset time is: 2024-11-25 08:23:16