2.09.2005

 

The physics engine

I had been thinking about this, and I think the best way to approach it would be to create the most generic physics engine we could come up with (no matter how small), and have it be a class. It would be either one instance for the whole game, or one instance per character. I think it would be better if it were one per game, to save space. Now the question is how would it work? Well let's ask ourselves, what do we need to implement?


  1. Jumping. Given the speed and strength of a character, I want a function that will be able to calculate determine the velocity given certain variables.

  2. Falling. Each cycle of execution the downward speed of the character would increase, depending on the gravity in the physics class instance.

  3. Knockback. Given the attacker's strengh and the defender's defense and bool isBlocking variable, I want to give the defender a nice knockback.


These are the most important things we want to do. How exactly would the class work? I would like it to work on pointers and not depend on other classes we have created. For example, say that:
PhysicsEngine* phys =
new PhysicsEngine(float gravityConstant, float wind, float dragCoefficient);


So then in the character's update function,

if(char presses jump button) {
phys->jump(speed,strength,&dy);
}

What we would then like to happen is that the character's dy gets a new float value, depending on the physics engine, the speed and strength. I think this seems like a good design for it. I will add all of this in more detail to the technical spec very soon.


Comments:
This comment has been removed by a blog administrator.
 
The physics engine should be more abstract. It shouldn't care whether the thing occuring is a jump or a knockback or what have you. It should just care that it has some thing acting on something else and it has to know how velocities interact and such.

Also: gravity should be a global constant. No real reason for gravity to have a different value at different times.

So, the physicsEnginge class will either be much simpler, or may actually get dissolved into the character/projectile classes as public methods or somehthing.
 
Alright. Change of plans. The thinking was a bit too complex on this one. So all in all, it would be better to implement physics stuff into the Character class. Each character will have a Jump and ReceiveKnockback functions. Jump would depend on on each character's jumpSpeed variable. And knockback on the strength and the hitter's strength and other variables. Keep it simple.
 
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?