Tank physics

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.

link is broken

Fixed.

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.

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

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!

Runs great here on my new laptop.

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?

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

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)
[/quote]
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. :slight_smile:

Hahahaha, that’s what happens when you change a method to final and you don’t compile its subclasses :stuck_out_tongue:
Wait until he fixes this.

Fixed.

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.

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?

  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.

Strange it not always slide but it do sometimes.