Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (116)
games submitted by our members
Games in WIP (563)
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- how?  (Read 2709 times)
0 Members and 1 Guest are viewing this topic.
Offline CommanderKeith
« Posted 2006-07-12 14:01:15 »

Hi,

I really want to add physics to my <a href="http://www.freewebs.com/commanderkeith/STG.jnlp">2D tank game</a>.  Right now it just does collision detection.  The majn reason I want physics is so that when I run into a wall the tank doesn't just stop but can keep on moving, and so that I can have cooler weapons like harpoons, actual explosions, ramming, etc.  How should I implement the physics? Everything in the game world has a 2D polygon already.  What fields do I need to add to each game object & how should I resolve the forces, etc without having infinite loop problems?  My game uses time based movement.

thanks,
Keith

mass
xVelocity
yVelocity
angularVelocity
forceSize
forceAngle
forcePoint

Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #1 - Posted 2006-07-13 11:03:41 »

A simple approach is outlined in this paper. It's not perfectly realistic, but it's relatively simple to implement, and looks pretty good.
It's an emergent system, so the complex global behaviour arises automagically from simple local interactions - this means you don't have to have any physics knowledge, or indeed much maths (vectors is about it, there isn't even any trigonometry).
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #2 - Posted 2006-07-13 11:25:50 »

A simple approach is outlined in this paper. It's not perfectly realistic, but it's relatively simple to implement, and looks pretty good.
It's an emergent system, so the complex global behaviour arises automagically from simple local interactions - this means you don't have to have any physics knowledge, or indeed much maths (vectors is about it, there isn't even any trigonometry).

Someone around here has already done a java implementation of that ( http://www.java-gaming.org/forums/index.php?topic=399.0 ) although I'm not sure if it's still avaliable.

On the other hand doing your own implementation isn't as hard as it looks, the math is much simpler than most physics methods and it requires much less tinkering to get stable. Definately recommended for 2d physics.

Edit: Ha, obviously I type too slowly. Smiley Bleb you should put that physics stuff back online, it was quite cool.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ryanm

Senior Member


Projects: 1
Exp: 15 years


Used to be bleb


« Reply #3 - Posted 2006-07-13 11:40:34 »

Quote from: Orangy Tang link=topic=14346.msg113994#msg113994
Someone around here has already done a java implementation of that ( http://www.java-gaming.org/forums/index.php?topic=399.0 ) although I'm not sure if it's still avaliable.

Err, yeah... someone...  Roll Eyes

I could dig it out again, but it's been years since i did anything to it, it could probably do with some refactoring, etc, etc.

In any case, using my crappy code won't be as fun as doing it yourself.

edit: Have just reread the linked thread Grin - brought back the memories of how "conversing" with VRML_Java_Animator was like bathing in pure, concentrated crazy.
Offline CommanderKeith
« Reply #4 - Posted 2006-07-15 13:41:04 »

Thanks very much for those links.  That method sounds quite amazing, its just a pity I don't know vector or matrix maths.  I'd actually be happier if it was physics & trigonometry.  The method outlined in the article opened my eyes to what can be done - like I never thought of the possibility actually allowing the vehicle go inside a wall just a little so physics can be calculated in a stable way.  Interesting techniques, I'll have to do more reading.

Offline JAW

Senior Member


Medals: 2



« Reply #5 - Posted 2006-09-05 22:19:06 »

Dependend on what you need, for startes it is x and y velocity or velocity and direction. Id take both redundant but makes things easier. You need to compute one out of the other anyways sooner or later..

On collision you need to calculate momentum / impulse. Momentum p = m * v (mass * velocity).
The velocity of the other object then is v = p/m. Velocity gets greater when the other object has a lesser mass. The direction of the movement is
away from the center of the colliding object. So when a tank hits a crate, the crate moves away from the center of the tank. You just need to calculate the angle based on x and y positions of the tanks and crates center.

Elastic collision is a little different, you need to look this one up. The tank would then bounce back when hitting a wall.

Ballistics are easy, just handle horizontal and vertical different. Horizontal speed is constant or reduces at a constant rate if you want it. Vertical speed reduces by gravity. Precomputing the point of impact or computing a shooting angle to hit a certain spot is a little difficult.

There is a book "Beginning Math and Physics for Game Programmers" - Wendy Stahler. It covers all basics.
Any physics book does it as well.

Need something special?

-JAW
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.

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

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

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

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

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

BurntPizza (32 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24:56
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!