Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  2D Physics ala GTA 2  (Read 4595 times)
0 Members and 1 Guest are viewing this topic.
Offline TheMatrix154

Junior Member


Medals: 2



« Posted 2009-04-30 13:26:25 »

Hi Com,

i want to write a little 2d top-down racer. but i don't get a starting point for the "physics" behind. i've read some articles like Adanced Character Physics but it don't want to go into my head. is there something like dummy-physics-step-by-step-tutorial? the physics don't need to be realistic, the gameplay is more important for me. i know some self-teached vector math but i've no experience with matrix math.

thx in advance

and btw: yes my first official question here, and sorry for any grammar / word mistakes, english isn't my natural language.

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2009-04-30 13:56:03 »

"Advanced character physics" is a nice approach, but IMHO for GTA style physics you might be better off with a more traditional rigid body simulation.

The original 2.5d GTA games actually had quite a complicated engine simulation - IIRC it tracked things like torque, horsepower and revs, and for the actual cars the wheel position and orientation affected the forces that would be applied (rear-wheel-drive car handled differently from a front-wheel drive one).

If you don't want to delve into the icky physics details yourself it might be easier to use a physics library (either a 2d one with gravity turned off or a full 3d one where you restrict movement in the z axis).

If you want to do it yourself I'd start begin simply and build up. Start with the basic <a href="http://en.wikipedia.org/wiki/Equation_of_motion">equations of motion</a> and you can have a sprite with basic speed and acceleration applied based on key input.  Basic <a href="http://cgp.wikidot.com/circle-to-circle-collision-detection">circle vs. circle</a> collision detection is easy, and so detecting when two objects intersect and altering their speed will get you something akin to snooker balls. Add in orientation, upgrade to rotated rectangles rather than circles, add friction from wheels, etc. etc.

Also more reading here: http://www.java-gaming.org/topics/physics-library-for-top-down-racer/19653/view.html

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline CommanderKeith
« Reply #2 - Posted 2009-04-30 14:11:50 »

Check out JBox2D and Phys2D for physics simulations, they're both very good.

Also, Kev Glass (author of phys2d) made an awesome physics car game (2d side view with gravity, not top down) here:
http://www.java-gaming.org/topics/4x4k/19586/view.html

It uses the vertlet integration technique in that paper you referenced. You should ask kev about it, this is his web page: http://slick.cokeandcode.com/

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline TheMatrix154

Junior Member


Medals: 2



« Reply #3 - Posted 2009-04-30 18:41:16 »

Thank you very much Orangy Tang and CommanderKeith. I'll have a look at the basic equations of motion to learn the basics first, because i want to understand how it works. If i don't get the point i'll have a look at Phys2D and JBox2D.

thx

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11


Game Engineer


« Reply #4 - Posted 2009-04-30 18:55:59 »

You can also check out Daid's Ludum Dare 13 entry, which was an interesting vector-based top-down game where you drive cars in a city, and it used Box2D for the physics. Windows only, unless you want to compile it. Also, this isn't in Java, I was more posting this so you could see how this concept can work with Box2D. When you mentioned your question this game is immediately what I thought of, because I think he had very satisfying car physics and it was fun to drive around his city.

http://daid.mine.nu/pub/LD13_DigitalRoadJam_final.zip

See my work:
OTC Software
Offline TheMatrix154

Junior Member


Medals: 2



« Reply #5 - Posted 2009-04-30 22:57:39 »

Thanks a bunch Demonpants. It's really interesting.

Can somebody explain this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
void calcWheel(float angle, b2Body* wheelBody, b2Vec2 pos, float drive) {
        b2Mat22 wheelMat(angle);
        b2Vec2 wheelVelo = wheelBody->GetLocalVector(wheelBody->GetLinearVelocityFromLocalPoint(pos));
        wheelVelo = wheelMat.Solve(wheelVelo);
        wheelVelo.y = drive;
        wheelVelo.x *= -50;
        //TODO: limit wheelVelo.x for slipping
       wheelVelo = wheelMat.GetInverse().Solve(wheelVelo);
        wheelBody->ApplyForce(wheelBody->GetWorldVector(wheelVelo), wheelBody->GetWorldPoint(pos));
}


What is happening here?

My understanding:
- angle: relative wheel rotation in radians
- wheelBody: car body
- pos: relative wheel position from car
- drive: throttle (1f = max)

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11


Game Engineer


« Reply #6 - Posted 2009-04-30 23:21:51 »

Looks like it does some sort of individual physics calculation for the wheels. I'd recommend asking the author, because LD entries are unlikely to have good comments. Smiley

http://www.ludumdare.com/compo/author/daid/

See my work:
OTC Software
Offline zammbi

JGO Coder


Medals: 4



« Reply #7 - Posted 2009-05-01 07:59:13 »

Thanks a bunch Demonpants. It's really interesting.

Can somebody explain this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
void calcWheel(float angle, b2Body* wheelBody, b2Vec2 pos, float drive) {
        b2Mat22 wheelMat(angle);
        b2Vec2 wheelVelo = wheelBody->GetLocalVector(wheelBody->GetLinearVelocityFromLocalPoint(pos));
        wheelVelo = wheelMat.Solve(wheelVelo);
        wheelVelo.y = drive;
        wheelVelo.x *= -50;
        //TODO: limit wheelVelo.x for slipping
       wheelVelo = wheelMat.GetInverse().Solve(wheelVelo);
        wheelBody->ApplyForce(wheelBody->GetWorldVector(wheelVelo), wheelBody->GetWorldPoint(pos));
}


For a sec I thought Java had '->'. I was like wtf, when was that added. Then I noticed '*', damn c!

Current project - Rename and Sort
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #8 - Posted 2009-05-01 10:43:55 »

For a sec I thought Java had '->'. I was like wtf, when was that added. Then I noticed '*', damn c!

Heh, I've seen the following which is valid Java code:

1  
2  
// While x appraoches zero
while (x-->0) { ... }

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
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.

Riven (5 views)
2014-07-23 21:16:32

Riven (6 views)
2014-07-23 21:07:15

Riven (6 views)
2014-07-23 20:56:16

ctomni231 (40 views)
2014-07-18 06:55:21

Zero Volt (36 views)
2014-07-17 23:47:54

danieldean (30 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!