Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (754) Games in Android Showcase (229) games submitted by our members Games in WIP (842) 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
 Tank physics  (Read 7064 times) 0 Members and 1 Guest are viewing this topic.
appel

JGO Wizard

Medals: 80
Projects: 4

I always win!

 « Posted 2011-02-28 15:22:52 »

I'm working on this little game, where the player controls a tank in a top-down view.

First, maybe you can try what I have already, I'm using Slick + Phys2D:
http://gamadu.com/games/tankz/webstart/tankzgame.jnlp

You see how strangely it behaves, sliding etc.

The tank has two front tracks for turning, and they should have the same effect on the tanks movement like regular "wheels". Also, notice how the tank slides to the sides to the sides, not normal. Clearly I need some sort of vehicle support.
kappa
« League of Dukes »

JGO Kernel

Medals: 120
Projects: 15

★★★★★

 « Reply #1 - Posted 2011-02-28 15:39:41 »

link is broken
appel

JGO Wizard

Medals: 80
Projects: 4

I always win!

 « Reply #2 - Posted 2011-02-28 15:50:49 »

 Games published by our own members! Check 'em out!
lhkbob

JGO Knight

Medals: 32

 « Reply #3 - Posted 2011-02-28 18:07:57 »

I don't know what physics engine could help you, but bullet has some support for 3d vehicles, so you could look at how they solve it.  I think the heart of your problem is that the friction on the wheels doesn't work right.

A hack might be to increase the friction coefficient a lot so it doesn't slide at all.  Then either have higher forces to steer the tank, or artificially reduce friction while a key is held.  If fizzy gives you enough control to specify friction coefficients for multiple directions, just increase the amount of friction that's orthogonal to the wheels which will prevent slipping but still allow it to move forward/back. This is all conjecture though, I've done a game with vehicles before.

dishmoth
 « Reply #4 - Posted 2011-02-28 18:37:13 »

You see how strangely it behaves, sliding etc.
Errm, no.  Sorry.  It thought it worked perfectly (and looked nice too).

I was moving/turning the tank quite smoothly with WASD, and obviously the turret follows (and fires at) the mouse pointer.  The resolution of my laptop isn't great, and I couldn't see the bottom of the window, so if there was anything happening there that I should've noticed, I didn't.

Only thing I can think of:  Is the frame rate fixed at 60/sec?  (That was what the FPS readout was saying, but I've noticed that my machine seems to run at that frame rate even if the application wants to run faster.)  And are you stepping the physics engine at the same rate as the graphics?  I understand that JBox2D(/Fizzy) prefers a fixed update rate, and if it's not getting it then that might explain the odd (machine specific?) behaviour.

If that's any help...

Simon

ra4king

JGO Kernel

Medals: 508
Projects: 3
Exp: 5 years

I'm the King!

 « Reply #5 - Posted 2011-02-28 22:51:47 »

I see nothing odd at all. The game runs quite nicely and smoothly on my Windows 7 64-bit with crappy Intel GMA card.

The tank seems to get stuck (WASD doesn't work anymore) when I go beyond borders of the window.

Other than that, the graphics are quite nice!

Keep up the good work!

zammbi

JGO Coder

Medals: 4

 « Reply #6 - Posted 2011-02-28 23:24:12 »

Runs great here on my new laptop.

Current project - Rename and Sort
appel

JGO Wizard

Medals: 80
Projects: 4

I always win!

 « Reply #7 - Posted 2011-03-07 17:13:05 »

I've made some updates. (Link updated)

I replaced Fizzy with Phys2D.

Phys2D, Fizzy nor Jbox2D provide any vehicle support, and I clearly need that. Seems kind of strange there is no vehicle support for 2D games in Java?
lhkbob

JGO Knight

Medals: 32

 « Reply #8 - Posted 2011-03-07 17:22:17 »

Most vehicle support is pretty hackish, even in 3D engines.  Try looking at how Bullet does it: http://code.google.com/p/bullet/source/browse/trunk/src/BulletDynamics/Vehicle/btRaycastVehicle.cpp

Mind you, I haven't read this code but if have more general questions about Bullet, both jezek and I have done a lot of porting work on Bullet (I'm working on my own adaptation, I've not contributed to JBullet).

daif

Junior Newbie

 « Reply #9 - Posted 2011-03-15 10:30:02 »

Hey there.  I've tried to play it, but it doesn't run on my machine.

Win7 pro 64bit, 4gb ram, Intel Core2Duo 3GHz

Quote
java.lang.VerifyError: class com.tankz.systems.PhysicsSystem overrides final method processEntities.(Lcom/artemis/utils/ImmutableBag;)V
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access\$000(Unknown Source)
at java.net.URLClassLoader\$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Same on my notebook (Win 7 Home Premium, 3 GB RAM, Intel CoreDuo 1.3 GHz) btw.
Both have Java 6 (Build 1.6.0_24-b07) installed.

Am I doing anything wrong? I am pretty new to Java, JGO and everything.

 Games published by our own members! Check 'em out!
ra4king

JGO Kernel

Medals: 508
Projects: 3
Exp: 5 years

I'm the King!

 « Reply #10 - Posted 2011-03-15 20:39:31 »

Quote
java.lang.VerifyError: class com.tankz.systems.PhysicsSystem overrides final method processEntities.(Lcom/artemis/utils/ImmutableBag;)V
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access\$000(Unknown Source)
at java.net.URLClassLoader\$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Hahahaha, that's what happens when you change a method to final and you don't compile its subclasses
Wait until he fixes this.

appel

JGO Wizard

Medals: 80
Projects: 4

I always win!

 « Reply #11 - Posted 2011-03-15 23:39:52 »

Fixed.
daif

Junior Newbie

 « Reply #12 - Posted 2011-03-16 16:19:28 »

I like it very much. driving around and shooting feels very smooth and "realistic".

appel

JGO Wizard

Medals: 80
Projects: 4

I always win!

 « Reply #13 - Posted 2011-03-16 16:54:06 »

I like it very much. driving around and shooting feels very smooth and "realistic".

It's nowhere near the "realism" I'm seeking, and I'm quite shocked that people think it feels good.

1. Shooting from the sides (tower rotated 90° relative to tank base) should not produce a recoil effect on the tank (it should not move sidewise)
2. It should not slide on the sides.
3. Turning isn't accurate, it should rotate depending on front wheels.
daif

Junior Newbie

 « Reply #14 - Posted 2011-03-16 17:39:38 »

I think I get what you mean. It feels a bit like sliding with the back, when you drive in circles.
Maybe your rear wheels should make a turn aswell? Otherwise you have to make bigger steeringcircles, which could make the game less fastpaced. But then everything (shooting, driving) should be more heavier and less agile (like the shootinganimation of the cannons, which i really like).
What do you want to achieve?

pitbuller
 « Reply #15 - Posted 2011-03-31 20:04:32 »

I like it very much. driving around and shooting feels very smooth and "realistic".

It's nowhere near the "realism" I'm seeking, and I'm quite shocked that people think it feels good.

1. Shooting from the sides (tower rotated 90° relative to tank base) should not produce a recoil effect on the tank (it should not move sidewise)
2. It should not slide on the sides.
3. Turning isn't accurate, it should rotate depending on front wheels.

1. Is pretty easy task to fix. Count recoil by yourself and don't let phys2d do that for you. When creating ammo check it disabled immediatly( enabled(false) ) Then count impact only for you tank normal vector. After that enable ammo. Ugly but effective.

2. This is hard. Maybe you should use big enough friction and if you want some sliding add it by yourself only when needed.

3.  Can't figure any solution.
Gudradain
 « Reply #16 - Posted 2011-03-31 23:33:05 »

Strange it not always slide but it do sometimes.
Pages: [1]
 ignore  |  Print

 DesertCoockie (21 views) 2018-05-13 18:23:11 nelsongames (69 views) 2018-04-24 18:15:36 nelsongames (66 views) 2018-04-24 18:14:32 ivj94 (750 views) 2018-03-24 14:47:39 ivj94 (80 views) 2018-03-24 14:46:31 ivj94 (604 views) 2018-03-24 14:43:53 Solater (96 views) 2018-03-17 05:04:08 nelsongames (169 views) 2018-03-05 17:56:34 Gornova (387 views) 2018-03-02 22:15:33 buddyBro (1047 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 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