Setting up a damage indicator and need help

(ZVWolf) #1

Hopefully somebody can help me with this problem I am having. I think it may just be something I don’t understand or a stupid mistake but anyways this is my problem:

I have three objects and bellow I have listed them along with their properties:

DamageBar
Integer - Damage_Value: 0

RedTank
Float - RDamage: 0.000
Boolean - RedPlayer: True

Bullet
No Properties

So hopefully you may know now what this game involves ;)… anyway the DamageBar is a plane that is attached to an IPO that controls its growth on the X axis. Now what I have setup to happen is this:

The Bullet object, when a it detects a collision, adds a value of 50 to RedTank’s RDamage property and then an Always sensor attached to RedTank connects to a python script (called: HUD_Controller) which is as follows


import GameLogic as g
cont = g.getCurrentController()
own = cont.getOwner()

g.Damage_Value = own.RDamage

Now over in the DamageBar object we have an Always sensor connected via an AND controller to an IPO Actuator which is set to property and points to Damage_Value.

When the game is run and the collision happens, the damage bar doesn’t move as it should. Also just to see if it was my IPO setup I set the DamageBar’s property Damage_Value to 50 manually and then ran the game and the bar had increased so the IPO setup is working fine.

If anyone could help me with this, it would be great.

Thanks

ZVWolf.

P.S Also I am not sure if the python script is necessary, perhaps it isn’t. Oh and the other thing is, no errors are returned in the command prompt window that accompanies blender.

0 Likes

(Mico27) #2

whats the property of your bullet? no actor? simple actor? dynamic? rigidbody?
coz the bullet as to be set to dynamic if you want him to detect a colision. you can set the bullet to dynamic or if you really dont want it you’ll have to set to dynamic the object you want it to collide to. one of two ogject must at least be dynamic to detect a collision

0 Likes

(ZVWolf) #3

Thanks for the reply Mico27 but I have actually fixed my problem by starting from scratch and also following the basic idea of Socials’ tutorial : (thanks social)
http://www.blendenzo.com/tutHealthBar.html

Anyway everything is running fine now!

Thanks Again,

ZVWolf

0 Likes

(goldentaiji) #4

:confused:Hmm… where does it say Social wrote that tutorial? I believe it may be someone else… wonder who that may be… lol.

But I’m glad the tutorial helped out.

  • Just a side note. The tutorials on Blendenzo’s site is a collection of multiple tutorials written by more than one person.

Jason Lin

0 Likes

(ZVWolf) #5

I am so sorry goldentaji, thank you for the tutorial! haha… it was 1am in the morning when I finally got it all working and replied to this email so brain activity, I guess, wasn’t at the highest level it possible could have been, but yeah, I don’t know how I didn’t see the ‘by goldentaji’.

Anyways sorry about that,

ZVWolf

0 Likes

(The Red Hand) #6

I’ve been looking for a way to improve that tut and try and figure out how to put a bit of randomization to it so you don’t always knock out 20hp. Any ideas?

0 Likes

(ZVWolf) #7

Yes, The Red Hand, I was thinking the same thing, though more along the lines of if hit by a different type of bullet or missile it would take off different amounts of the health bar, though that wouldn’t be difficult at all to do.

Anyway I looked through some python and gamelogic documentation on blender3d.org and found an interesting function called getRandomFloat(). I added it to goldentaji’s script in his tutorial and this is what i came up with:

import GameLogic as g

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

laser = cont.getSensor("Laser")
randnum = int(g.getRandomFloat()*80)+10

if laser.isPositive() and own.energy > 20:
   own.energy -= randnum

#I added this so I could know what numbers are being generated but it isn't necessary
   print randnum

What happens here is getRandomFloat randomly generates a number between 0 and 1 and has about 7 or so decimal places, so then assuming the random number generated is 1, it is then multiplied by 80 and 10 is added equaling 90 and thus giving us the highest possible number that can be created. If the number generated was 0 then 0*80+10=10 and this is the lowest possible number that can be generated, giving us a range of 10…90. So you can change those numbers to suite your needs. Oh and Int takes away all those bothersome decimal places.

Anyways, I tried that out and it worked fine. Hopefully that helps.

ZVWolf

0 Likes