Optimizing my game

BlitzMax Forums/BlitzMax Beginners Area/Optimizing my game

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

To the "how much damage" thing:

To calculate the "velocity" you need to 4 Points (Point = x,y)
Obj1.OldPosition, Obj1.NewPosition
Obj2.OldPosition, Obj2.NewPosition

OldPosition = X,Y
NewPosition = X+dx, Y+dy

Having 4 Points you can calculate the angle between the 2 Lines:
Line1(Obj1.OldPosition, Obj1.NewPosition)
Line2(Obj2.OldPosition, Obj2.NewPosition)

The one with "Mass*LineLength" bigger than the other object is the "winner" of a collision (more force, cinectic energy mass/2 * speed^2)

Now you have a energy (cinectic energy) connected to a direction (Line1 and Line2).

The bigger "energyline" (linelength * mass) will be the hypothenuse the other is mostly the ankathede (dunno if its the same in english).


cos(energylineSmall / energylineBig) = angle of power the objects hit together with.

The smaller the angle the bigger the impact (like a train colliding into another train driving into the straight opposite direction, compared to a car crashing into another on the crossroad).

If the Angle is near 180° then Object1 moves faster than Object2 (on the same movement-path) and hitting it will do a ForceDamage of Force1-Force2).

Assume Object1 has very less Force than Object2, then damage done to Object1 is (Force2 - Force1). Object2 would have a damage done of Force1.


With the collision angle and the damage (forces) you can additionally calculate the new direction the objects take.



Before I write too much without bringing some effort into it (for you).
This was just a bit of brain-smashing to give some ideas.


To add some kind of summary:
Damage done is force*angle of collision.
Force is mass/2 * speed^2 (E_cinetic).
New direction of movement is angle of collision (0-100%) * PathObject1 + (100%-angle of collision)*PathObject2).


bye
MB