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 / ball bouncing off bat using physics

Author
Message
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 13th Feb 2013 15:05
hi, another problem!




in this small test,how do i make it so that once the ball hits the bat,it will shoot off at another angle(depending on where the ball hits the bat, and a regular speed as long as it reaches the edges of the screen! tried a few ways but couldn't do it,at the moment this code doesn't try as i didn't want to include my own junk that didn't work!

Hail to the king, baby!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 13th Feb 2013 15:58
After you set the initial positions of the bat and ball, you need to apply a force or impulse (impulse is better, I think) to the ball and then let the physics engine take over.

If you want the ball to not slow down over time (as though due to air drag), SetSpritePhysicsDamping to zero.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Feb 2013 16:54


Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 13th Feb 2013 18:29
That's the idea!

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 13th Feb 2013 19:43 Edited at: 13th Feb 2013 19:45
I think i tried something similar that way before,but the ball becomes rather erratic,it looks as though the values become accumulative ? When it doesnt hit the bat, the ball also still loses its force

Hail to the king, baby!
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 13th Feb 2013 20:16
Try turning friction off and max restitution:
SetSpritePhysicsFriction(ball,0)
SetSpritePhysicsRestitution(ball,1.0)
SetSpritePhysicsFriction(bat,0)

If you want to see it gain speed, make the ball's restitution greater than 1.0. It can get quite frenetic and is fun (if not necessarily useful to the app).

If you keep the Restitution at 1 or less, it does not gain energy.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 13th Feb 2013 21:37 Edited at: 13th Feb 2013 22:20


shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 14th Feb 2013 10:12
tnx markus.it is more like what i want,which part would i change to make the ball go slower? the use of some speed var is needed as i will be changing the balls speed,but it needs to start alot slower than it is atm

Hail to the king, baby!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Feb 2013 12:49
-10 is the impulse up at start

SetSpritePhysicsImpulse( ball, getspritexbyoffset(ball),getspriteybyoffset(ball), x#,-10 )

setspritephysicsvelocity
getspritephysicsvelocityx
getspritephysicsvelocityy
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 14th Feb 2013 15:29
do you mean the ones that are remmed out... in the main loop,i unremmed them and made the last value from 0 to -10,it starts off ok,but becomes really erratic again at some point!

Hail to the king, baby!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 14th Feb 2013 17:37
no this was for bat.
the physic mode KINEMATIC is special i try before DYNAMIC.
you must read the docu for SetSpritePhysicsOn

i mean at if state=1 ...
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 14th Feb 2013 21:33
I think I got it now thanks again, but this way has led to another problem, the ball can sometimes ping pong up and down (at least vertically) forever with out shifting horizontally,therefore stuck in a loop, not really good if i have some blocks indestructible!

Hail to the king, baby!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 15th Feb 2013 08:17
hmm, you can memory the last time down and if he > some seconds
in the air give him a random impluse x,y
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 15th Feb 2013 10:50 Edited at: 15th Feb 2013 10:57
you could yeh,trouble is though the blocks could be near an edge or the other side of the screen so the time would be different but still the same problem! how would one simply eliminate the angle from having a 0 or 90 value so that it can never do such straight angled movements!
Also I found out the cause of the balls sometimes erratic movements, when the ball hits the side of the bat then the balls angle is changed,causing some speedup of the ball!

Hail to the king, baby!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 16th Feb 2013 14:51 Edited at: 16th Feb 2013 14:52
ups
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 16th Feb 2013 14:51
its physic, you can try to set the angle of the bricks a little bit,
try 90.1 (+-with random) instead of 90 degree, just a idea.
make a extra impulse like a pinball game what shows you a tilt
after you use it to much.
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 16th Feb 2013 20:22
I suspected as much! Perhaps I should not use physics! Just a shame as it would've done a lot of house work for me automatically

Hail to the king, baby!
TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 16th Feb 2013 20:26
Does it ping pong between two fixed blocks or between the bat and blocks ?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 16th Feb 2013 20:34
without physics i think you get the same problem.
can you make a screenshot if the ball doing endless ping pong?

Login to post a reply

Server time is: 2024-05-07 23:34:52
Your offset time is: 2024-05-07 23:34:52