Seems to work better like this:
rem
rem AGK Application
rem
rem Landscape App
SetDisplayAspect( 4.0/3.0 )
rem create two sprites
s1 = createSprite(0)
setSpriteSize(s1,5,-1)
setSpritePositionByOffset(s1,25,50)
setSpritePhysicsOn(s1,2)
s2 = createSprite(0)
setSpriteSize(s2,5,-1)
setSpritePositionByOffset(s2,75,50)
setSpritePhysicsOn(s2,2)
rem set gravity off
setPhysicsGravity(0,0)
mj = 0
rem A Wizard Did It!
do
rem print results
print("Force = "+str(f#))
rem mouse grab
px# = getPointerX()
py# = getPointerY()
if getPointerPressed()>0
hit = getSpriteHit(px#,py#)
if hit>0
mj = createMouseJoint(hit,px#,py#,1000000)
endif
else
if mj>0
if getPointerState()>0
setJointMouseTarget(mj,px#,py#)
else
deleteJoint(mj)
mj = 0
endif
endif
endif
rem detect collision
if getPhysicsCollision(s1,s2)>0
f# = getCollisionStrength(s1,s2)
endif
Sync()
loop
function getCollisionStrength(iSpriteIndex1,iSpriteIndex2)
rem get all forces
forceX1# = GetSpritePhysicsVelocityX( iSpriteIndex1 )
forceY1# = GetSpritePhysicsVelocityY( iSpriteIndex1 )
forceX2# = GetSpritePhysicsVelocityX( iSpriteIndex2 )
forceY2# = GetSpritePhysicsVelocityY( iSpriteIndex2 )
rem get total force left after collision
forceX# = forceX1# + forceX2#
forceY# = forceY1# + forceY2#
force# = sqrt(forceX#*forceX# + forceY#*forceY#)
endfunction force#
EDIT: But it doesn't allow for mass
or angular velocity. It's only really a basic method.
this.mess = abs(sin(times#))