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 / AGK physics question

Author
Message
shadey
14
Years of Service
User Offline
Joined: 25th Jan 2010
Location:
Posted: 25th Jan 2013 11:57
How would I continually apply a force to a sprite so that i could for instance keep a ball bouncing around the screen forever ?!

Hail to the king, baby!
The Zoq2
15
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 25th Jan 2013 12:12
for bouncing, you could use the SetSpritePhysicsRestitution command
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 25th Jan 2013 15:37
Use a combination of SetSpritePhysicsFriction, SetSpritePhysicsRestitution and SetSpritePhysicsDamping

Set SetSpritePhysicsDamping to 0 to stop all 'wind' resistance (slows it down over time.

Set SetSpritePhysicsFriction to 0 to stop friction when it hits walls.

Set SetSpritePhysicsRestitution to 1 so that it keeps all of its bounce.

You can have real fun by setting SetSpritePhysicsRestitution greater than 1 and it gains energy. I nearly laughed myself silly watching my character frantically bounce between walls the first time I did this.

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: 29th Jan 2013 23:47 Edited at: 29th Jan 2013 23:48
(its the same as Friction=0)
if the Velocity is under a minimum you can resize the value in the
Get XY direction
x#=getspritephysicsvelocityx(Level.Ball.spr)
y#=getspritephysicsvelocityy(Level.Ball.spr)

v#=sqrt(x#*x# + y#*y#) //vector length

x#=x#*1.01
y#=y#*1.01

SetSpritePhysicsVelocity(Level.Ball.spr,x#,y#)

Login to post a reply

Server time is: 2024-11-24 08:55:12
Your offset time is: 2024-11-24 08:55:12