Game Development Community

Physics Timing Issues

by Ray Gebhardt · in Torque Game Builder · 03/01/2005 (7:54 pm) · 9 replies

I am having a few issues with the the physics. I have a character that needs some basic platformer style physics (think Super Mario). Basically the little knight dude i have has the ability to jump and walk around. The problem is, that he can jump, but he jumps different heights on all machines. So I have gravity setup by doing the following after creating the scenegraph:

%scenegraph.setConstantForce("0 1000", false);

To make him jump I use:

$player.setImpulseForce("0 -1000");

I am using a materials datablock that looks like the following:

datablock fxCollisionMaterialDatablock2D(playerMaterial)
{
	friction = 0.0;
	restitution = 0.0;
	relaxation = 1.0;
	density = 0.0001;
	forceScale = 1;
	damping = 0.7;
};

If anyone knows why that's not working correctly, could you help me out? I am kind of new to these kinds of physics systems, so its probably entirely my fault. And if there are any other issues you think this code might cause, it would be nice to know too.

#1
03/02/2005 (2:28 am)
Hmmm, you should have consistency, independant of OS or timings as long as the relative FPS differences are not too extreme although even then, the differences shouldn't be that noticable.

I'll play with this as soon as I can (so many things to resolve at the moment) so I've just added it to my growing list.

Sorry for any inconvienience this may be causing.

BTW: Are these tests all on the same OS?

- Melv.
#2
03/02/2005 (6:16 am)
Actually the tests were on the same OS. I actually tried making my computer "emulate" a slower machine, by scheduling a block of code that just looped a whole bunch of times. I noticed that my character would jump a lot higher with the loop added, even though it didn't really seem to have much of an effect on framerate. I have only done testing on Windows XP and 2000 so far.
#3
03/02/2005 (6:23 am)
Okay, thanks.

I'll investigate this problem. It's on my list. :)

- Melv.
#4
03/02/2005 (11:22 pm)
Nevermind Melv, it was an ID10T error. The physics work extremely well from machine to machine. I was doing setImpulseForce for the jumping, when i really should have did a setConstantForce on the player object. Then I would just have to have a scheduled function that cancels out the setContantForce. The the jumping physics for the player should perform almost exactly the same on all machines. Well unless you know some other ways thats better. ;)
#5
03/03/2005 (12:49 am)
@Ray: It's one of those things that you can do with schedules but the problem with doing that is if the system gets busy and the schedule doesn't happen exactly as requested, you could have small differences between how it works albeit on the same machine, nothing to do with different platforms.

So you were scheduling impulse forces for gravity as well as the player jumping?

I'd want more determinism so what I'd probably do is apply a constant force for gravity either at the scene-level (which means you've got to mark static stuff like levels as immovable) or apply a constant force (gravitic? = true so it is independant of mass) and then just apply a linear impulse for the jumping. This way, everything is handled deterministically by T2D, no schedules.

This is perhaps your new method but I thought I'd try to clarify the way to go for others. :)

Physics tutorials to come!

- Melv.
#6
03/06/2005 (4:07 pm)
Hey Melv,

The way I'm doing gravity (now that I've thought and fiddled a lot) is to set a constant force "0 4000" on the scenegraph, and on each of my tile layers I have a constant force "0 -4000" to balance it (so gravity doesn't apply to the layers). then when the player jumps I use $player.setImpulseForce("0 -2000", false).

How would you suggest allowing world collisions but not applying gravity to the world? Does my force balancing make sense? Or should I use an immovableMaterial like I think you suggested above? Or does it just end up the same?

Edit: Deleted all the nonsense that was a problem on my end.
#7
03/06/2005 (5:09 pm)
@Melv: I've been applying a constant gravitic force to a ball that is shot out of a cannon using a polar impulse force, but I seem to get the same issue as Seth was getting: every once in a while one of the balls will be shot from the cannon with far more force than I assigned or a bit less. I have the values set permanently right now, until I get the game further along, so there shouldn't be any variance in any force... yet there is. I thought it was the same issue Seth was having, but he seems to have fixed it.
#8
03/06/2005 (5:14 pm)
D'oh! Not immovableMaterial. There's actually a setImmovable method! Aha!
#9
03/07/2005 (1:03 am)
@Seth: Yes, if you look in the C++ code, it actually calls "setDensity(0)" which equates to the same thing. Just though it'd be better than the magical number in density.

@Matt: We've still got work to do on the physics code but you should get pretty deterministic results as long as your frame-rate isn't varying drastically or you've got a permanently bad frame-rate.

We'll be continuing work on the physics stuff though. Sorry for any problems you're encountering.

- Melv.