Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Physics- Something that's been holding back me for a while  (Read 285 times)
0 Members and 1 Guest are viewing this topic.
Offline Zhon

Junior Member


Medals: 4



« Posted 2014-02-01 19:42:39 »

It's been quite some time that I've been trying to get something done, but I am getting stuck on a pretty ridiculous obstacle.
All I wanted to do was a plataformer, with physics similar to Terraria (not the building/break part, just the physics). i.e 2D grid-like world with moving entities.

I think the part I'm messing up is the algorithm, can you guys help me get past this?
Here's what I thought while writing this thread:
On each game loop:

- Iterate through all entities
-- Update their positions based on their current motions (posX += motionX and posY += motionY)
-- Check if they collide with the grid-world (blocks) and update their positions so they don't overlap with the blocks
- Iterate through all entities a second time
-- Inside the current entity iteration, iterate with all entities that are not the current one
--- Check if they collided, if they do, do the following:
---- Teleport the entity to where the collision happened [¹]
---- Give damage or something, basically call some onCollidedWith method, make it invencible for 1 second or 2

I just improvised this algorithm, because I don't have anything else in mind? What should I do to have a properly functional 2d grid world?
Btw this part: [¹] - Brings me some confusion because, since there are many entities, I think it would cause some physical bugs in case 3 entities were moving and 2 collided where there shouldn't have a collision due to another collision that should have taken place before the previous collision.
This is very hard to explain but basically, what confuses me is the order in which the collision responses are to be executed.
Besides, my algorithm also looks very slow (iterate through all entities 3 times?).

My last resort is to humbly ask for a less poor algorithm, that would be responsive but at the same time not overwhelmingly hard to implement, this all must be very simple and the fact that I've been stuck past this point has been bugging me so much. Any input is appreciated.
Offline ctomni231

JGO Wizard


Medals: 99
Projects: 1
Exp: 7 years


Not a glitch. Just have a lil' pixelexia...


« Reply #1 - Posted 2014-02-01 19:46:23 »

Did you consider using a physics engine, like box2d?

I mean, it is possible to check all these entities, but you'll really have to make sure you have a really good algorithm, and perform culling correctly in order for it to work quickly enough.

Offline Zhon

Junior Member


Medals: 4



« Reply #2 - Posted 2014-02-01 19:54:45 »

Did you consider using a physics engine, like box2d?
Yes but I thought these provide too much for something that should be apparently simple.
Also, I'd like to resort to the less external engine as possible.

I mean, it is possible to check all these entities, but you'll really have to make sure you have a really good algorithm, and perform culling correctly in order for it to work quickly enough.
Although I ommited on the algorithm, the entities wouldn't iterate with the whole world, there would be array-grids holding the entities so they only iterate with those who matter. Also I don't know what culling is  Undecided
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline saucymeatman
« Reply #3 - Posted 2014-02-01 21:20:23 »

Culling is when we only run updates (or in this case physics checks) upon things that we know matter.

So if youve got a box thats off camera and isnt moving, why bother slowing your algorithm with it.

Edit :

Culling (Culled)
Something picked out from others, especially something rejected because of inferior quality.
Offline Zhon

Junior Member


Medals: 4



« Reply #4 - Posted 2014-02-01 21:29:18 »

Culling is when we only run updates (or in this case physics checks) upon things that we know matter.
So if youve got a box thats off camera and isnt moving, why bother slowing your algorithm with it.
So basically just skip the entities that aren't moving or offscreen?
Sounds simple enough I guess.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (34 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!