Falling Damage

It would be nice if in my game, hurling yourself from a peak ten thousand meters straight down wouldn’t be something you could do twice. I have a health bar and a method of damaging it, but how do you check for fall damage? Thanks.

well you could use

speed = own.getLinearVelocity[2]

and say

if speed > 50 and collision with ground.isPositive():
         own.health = own.health - 50

What is getLinearVelocity[2] ? Would that be the y speed, because I use z for down. But thanks.

I think that it is z. In many programming languages 0 is 1st, 1 is 2nd, 2 is 3rd… and so on.

I think that would be “speed < -50”, or something along those lines, because the default “down” is a negative vector on z.

I think the negative would be right. And x is zero then? Okay.

you could use

speed = own.getLinearVelocity[2]
print speed

and then jump down from what you want to be a killing height and read in the console how much velocity that is.

Does print work in blender? Ah, that will make thinks easier. Thank you again.

it will print to the console

Couldn’t you just do it with a invisable plane set to ghost and when you pass it then thouch ground you get hurt?

yeah and add a series of planes at different heights.

The Idea of boxes set at height is clearly described in the simple AI tutorial. It is an idea from Quake called a DeathFall

Basic Logic:

Collision with deathfall>> And>> Property Deathfall >Assign> 1

Collision with ground >> Property Deathfall = 1>> And >> End Object

Simple as that.

but with getLinearVelocity you could give the player different amount of damage depending on height.

And ‘print’ is probably the best thing ever.

I like the get Linear Velocity. And print will help.

Here is what I did:

cont = GameLogic.getCurrentController()
own = cont.getOwner()

speed = own.getLinearVelocity[2]
print speed

But I got an error message that looked like this:

Traceback (most recent call last):
File “getfall”, line 4, in (module)
TypeError: ‘builtin_function_or_method’ object is unsubscriptable

What do I do know?


speed = own.getLinearVelocity()[2]

(note the brackets before [2]) that should work. getLinearVelocity() is a method that returns a Python list, of which the [2] entry is what you want to get.

Oh, I see. I’m still a bit new to Python, so thanks.