Single Variable Force Script

Single Variable Force Script

Determines a dynamic object’s force in one variable. Good for force-based damage.
Needs one float property set at zero: iv

import GameLogic as g
import math
from math import sqrt
c = g.getCurrentController()
o = c.getOwner()
mass = o.getMass()
iv = o.iv
(vx,vy,vz) = o.getVelocity()
fv = sqrt(vx2 + vy2 + vz**2)
o.iv = fv
a = abs(fv-iv)*60
f = a * mass

ok… so how exactly do you use this script? it would be pretty cool to make some game with force based damage :smiley:

anyone? how do you use this script?

Yes, clarify your set-up here please, or at least give us an example of it’s uses. Thanks!


yeah i could really use this script… but how?

can you clearify the setup please , …

Seems straightforward to me.

It gets the mass and acceleration of the owner object, multiplies them together to get the force (f).

You can then use “f” as a value to reduce an objects health property.

so… how would you set it up in the BGE?

You’d set it up the same way you’d set up any other python script. The script just gives you a value its up to you to decide how to use it.

One example may be this…

Attach the script to an always sensor on the object you want to do the damage.

On the object you want to be affected by the damage, attach another script triggered by a collision sensor (or whatever you want) which minuses “f” (it’d have to be a global variable so GameLogic.f) from the objects health.

If you read up on some python tutorials, figuring out how to set these up becomes much easier and is probably easier than figuring out the rubbish explanations I give.

ok… i get what you mean… but how would you make text appear in the BGE because i could never really get that to work…

This might help you. It is not mine…

i cant get text to show up in the GE… and i followed the tut exactly…

Hey, nice script.
But max damage is 9. when it’s higher than that is goes down to 1 again:S
Can you fix that?

i wont be posting anything for about a week because my computer is messed up… (my personal computer, this is my moms computer :D) so c u again next week