Box2d - 2D physics

Previous topic - Next topic

AMateus

Hi,

I have been evaluating the possibility of making a top-down view game. But I need physics, so I start checking on box2d. But being a beginner in box2d I couldn't figure it out.

So, does box2d supports top-down view physics?

Thanks in advance,
António

Kitty Hello

it's 2D - no matter what direction you put it. If you want topdown, just disable gravity.

AMateus

Quote from: Kitty Hello on 2011-Sep-26
it's 2D - no matter what direction you put it. If you want topdown, just disable gravity.

Thanks you Kitty, it works well.

But I have a new, more problematic question... How to control jump in a top down view perspective with box2d?

Thanks in advance,
António

Slydog

Do you mean how to apply physics to a top-down view jump?
Is the jump towards the camera, and up and away from the 2d surface?
If so, that is no longer 2D!

Of course you could always simulate gravity on your own for jumping.
But you can't get Box2D to respond to your player landing 'on-top' of something, from the top-down perspective.
Since this would be 3D again.
Unless you can apply a force to inside an objects perimeter to simulate something hitting it from the top (or bottom).
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

AMateus

Yes, exactly that, and that was what I was afraid of...

I'll have to fake the jump and disable box2d collision (for example) while jumping or something like that =)

Thanks both.

Regards,
António

Slydog

I would love a 3D physics engine that works with GLB!

There is a port of Xors3D in these forums somewhere, here's the main product's site:
http://xors3d.com/

It is a paid for product, and only available for Windows and iOS.
I'm not sure if it is still being actively developed or not.

Ha, another option is to use Box2D for the main world top-down physics.
Then when you need the player to 'jump', create a new side-view world internally that contains the 'slice' of the 2D world along where the player is facing!  Respond to the physics and reapply the results to the top-down world!
Much easier if you limit the player to move fully up, down, left, or right.
If you allow directional movement, creating that 'slice' involves a lot more math!
Plus it wont account for when the player lands on half of a platform and should fall off or other events just away from that slice.
Should be very easy!   :D
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Kitty Hello

or you just "disable" the object's collision during the jumping, and after the "landing" you remove/destroy all objects that have contact with the player - or destroy the player if on spikes...

AMateus

Kitty that was my idea :)

Btw, is there a 3d physics engine for all the platforms supported by glb (desktop and mobile)?

Regards,
AMateus

Kitty Hello


bigsofty

Quote from: Slydog on 2011-Sep-26
I would love a 3D physics engine that works with GLB!

There is a port of Xors3D in these forums somewhere, here's the main product's site:
http://xors3d.com/

It is a paid for product, and only available for Windows and iOS.
I'm not sure if it is still being actively developed or not.

Ha, another option is to use Box2D for the main world top-down physics.
Then when you need the player to 'jump', create a new side-view world internally that contains the 'slice' of the 2D world along where the player is facing!  Respond to the physics and reapply the results to the top-down world!
Much easier if you limit the player to move fully up, down, left, or right.
If you allow directional movement, creating that 'slice' involves a lot more math!
Plus it wont account for when the player lands on half of a platform and should fall off or other events just away from that slice.
Should be very easy!   :D

iXors is already dead, the main programmer has left the project(Xors too long term IMHO), no development has been made since he left, don't waste your money... avoid!

Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Nathan

Could anyone help me with this please?  I've tried to get the example in the first post working, but with no luck, when compiling I get the following ...

Code (glbasic) Select

C:\Users\Nathan\AppData\Local\Temp\glbasic\gpc_temp1.cpp: In function `DGInt __GLBASIC__::b_BodyGetAngle(DGNat)':
C:\Users\Nathan\AppData\Local\Temp\glbasic\gpc_temp1.cpp:659: error: `RETURN' was not declared in this scope
C:\Users\Nathan\AppData\Local\Temp\glbasic\gpc_temp1.cpp: In function `DGInt __GLBASIC__::b_WorldDebug(DGInt, DGInt, DGInt)':
C:\Users\Nathan\AppData\Local\Temp\glbasic\gpc_temp1.cpp:745: error: expected primary-expression before "int"
C:\Users\Nathan\AppData\Local\Temp\glbasic\gpc_temp1.cpp:745: error: `i' was not declared in this scope
C:\Users\Nathan\AppData\Local\Temp\glbasic\gpc_temp1.cpp:745: error: expected `;' before ')' token


Steps I've taken to try and resolve this issue
- Un-install and re-install GLB
- Copy the attachment headers.rar into the "platform" folder
- Copy Include.rar into "Win32\Include\Bits" folder
- Delete the contents of the above Temp\Glbasic folder

And unfortunately each time I still get the above error.  Strangely, on my PC at work, it compiled first time without any errors or even copying those header/include files.  At work I have Windows7 32bit, at home I have Vista x64, could this be the problem?
Thanks.

Kitty Hello

somehow the box2d.gbas file has made inline code uppercase. I thought that was all fixed, but there might be a way to get it not to work still :(
Please just lowercase all IF, FOR and RETURN in the INLINE code fragments.

Nathan

Quote from: Kitty Hello on 2011-Sep-28
somehow the box2d.gbas file has made inline code uppercase. I thought that was all fixed, but there might be a way to get it not to work still :(
Please just lowercase all IF, FOR and RETURN in the INLINE code fragments.
Hi Kitty, thanks for your response.  I thought it might have been something as simple as that, but wasn't sure where the gpc_temp1.cpp was generated from.  I'll try it tonight at home.

It is a weird issue though, like I mentioned above, I downloaded the SAME zip file at work and at home.  At work, it's fine, at home, it errors.  The only difference is at work I use WinZip to unpack the file, at home I use the build in Windows Extractor.  Tonight at home I'll use WinRar or something.

Moebius

Shouldn't be a problem with what you used to extract the files.  It's a minor bug in the GLBasic editor - it shouldn't capitalise stuff in the 'INLINE' code, but it does sometimes...
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Nathan

Ah I see, thanks for that. :good:
Maybe an issue when the IDE is running on Vista and/or x64 bit OS.  There's a receipe for disaster right there.