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 / Detecting physics collision strength

Author
Message
mikkolah
12
Years of Service
User Offline
Joined: 13th Aug 2012
Location: Finland
Posted: 13th Aug 2012 11:05
Hi,

What is the preferred method to detect collision strength of physics sprites with AppGameKit?

Is there way to get box2d contact impulse information?
mikkolah
12
Years of Service
User Offline
Joined: 13th Aug 2012
Location: Finland
Posted: 13th Aug 2012 13:33
Forgot to mention that i'm using AppGameKit Tier 2
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th Aug 2012 14:01 Edited at: 13th Aug 2012 14:04
I would use the sprite velocity for each sprite involved and add the two vectors together. The result will give you something like a good idea of the collision force.

Example:
rem get all forces
forceX1# = GetSpritePhysicsVelocityX( iSpriteIndex1 )
forceY1# = GetSpritePhysicsVelocityY( iSpriteIndex1 )
forceX2# = GetSpritePhysicsVelocityX( iSpriteIndex2 )
forceY2# = GetSpritePhysicsVelocityY( iSpriteIndex2 )

rem get total forces
totalX# = abs(forceX1#) + abs(forceX2#)
totalY# = abs(forceY1#) + abs(forceY2#)
total# = sqrt(totalX#*totalX# + totalY#*totalY#)

rem get total force left after collision
forceX# = forceX1# + forceX2#
forceY# = forceY1# + forceY2#
forceLeft# = sqrt(forceX#*forceX# + forceY#*forceY#)

rem get force used in collision
force# = total# - forceLeft#

I would test the code though because I just made it up...

EDIT: Just made a few minor changes


this.mess = abs(sin(times#))
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Aug 2012 14:39
Would you not need to involve MASS in the equation?

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th Aug 2012 14:53
I guess that would be more accurate. Yes.

My quick example is probably ok for a game where most objects are similar in size.


this.mess = abs(sin(times#))
MrValentine
AGK Backer
13
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 13th Aug 2012 15:00
Thanks bax

mikkolah
12
Years of Service
User Offline
Joined: 13th Aug 2012
Location: Finland
Posted: 13th Aug 2012 16:41
Hmm. Didn't work as expected.

e.g. If sprite1 velocity is X and Y zero and sprite2 velocity is negative X and Y, result collision force will be always zero?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th Aug 2012 16:57 Edited at: 13th Aug 2012 16:58
Seems to work better like this:


EDIT: But it doesn't allow for mass or angular velocity. It's only really a basic method.


this.mess = abs(sin(times#))
mikkolah
12
Years of Service
User Offline
Joined: 13th Aug 2012
Location: Finland
Posted: 13th Aug 2012 17:11
Yeah, I had something similar to that already. Unfortunately it's not good enough. AFAIK only proper way is to use box2d impulse data.

I see there's agk::GetPhysicsWorld() function available, but there are just forward declarations available in distribution. Any idea which version of box2d used to compile AppGameKit?
Or even better, why not just include box2d headers in AppGameKit distribution?

That way I could implement my own b2ContactListener, and catch impulses in PostSolve function.
mikkolah
12
Years of Service
User Offline
Joined: 13th Aug 2012
Location: Finland
Posted: 13th Aug 2012 18:16
Ok, Box2D version seems to be 2.2.0

I was able to hack my way to create my own b2ContactListener
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 13th Aug 2012 19:10
Having access to b2d in tier 2 will certainly open up more possibilities!


this.mess = abs(sin(times#))
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 24th Aug 2012 13:15
mikkolah, would you mind sharing how you made your b2ContactListener?
Thanks!

mikkolah
12
Years of Service
User Offline
Joined: 13th Aug 2012
Location: Finland
Posted: 24th Aug 2012 17:23
Sure, here's simple example.

1. Download Box2d v2.2.0 from http://code.google.com/p/box2d/downloads/detail?name=Box2D_v2.2.0.zip&can=2&q=

2. Setup IDE include paths so that Box2D headers can be found.

3. Create new cpp file, where you include all box2d code.
For example Box2dContactListener.cpp


4. Call AttachB2ContactListener somewhere in the app::begin()


5. Implement some mroe code that uses contact data


- Mikko
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 28th Aug 2012 06:57 Edited at: 28th Aug 2012 07:07
I never got 2.2 implemented in dark gdk. Only 2.1 because I thought was more stable. Milk that is a great example. I never would of thought of that code you must have used box 2d before.

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.

Login to post a reply

Server time is: 2024-11-23 21:01:54
Your offset time is: 2024-11-23 21:01:54