Surviving Gamelogic / Python


(Krabat) #1

Okay, this is going to be a long one:

I have a cannon, i want to know where it hit’s and what it hits and which orientation the hit object has.

Try 1: The cannon emmits a visible bullet via add object, the bullet hit’s something and get’s destroyed, a python script to find out where and the orientation, add an empty at this position and add a bullethole in the target. doesn’t work because Attribute-error getHitPosition() occurs with a collision-sensor.

Try 2: The connon has a ray-sensor, getHitPosition works, the bullethole appears as planned. now i want to tell the hit object that it was killed a moment ago, ergo getHitObject(), to find out what was the Target. This gives me an empty string or “None”. Cool

Try 3: Every object gets a collision-sensor. when a bullet hit’s the object the script tries to find out where and creates a hole via an empty at this place: Attribute-error getHitPosition(). Nice

Well, i don’t know if i described the situation understandable but i’m a little bit… let’s say “unsatisfied” with the results so far…

Blender Publisher, Win98se, Python2.2

Anyone able to help me?

Krabat


(Krabat) #2

Forget it, i found a solution!

Gonna write a tutorial on what i learnt so far, don’t want any other Blenderhead having to drag himself through all this trial and error stuff.

The short Version of “How to blend some decent shooting”:

We take a Ray, a wall and a target. The target is parented to an empty.
The wall and the target have a boolian property named “Alive” (or whatever), set to “False” for the wall and “True” for the target. Additionally the target has property named “Damage”.
When the ray is triggered we check where it hit’s and in which angle to add a bullet hole (wall) or a little explosion (target) there. With:
HitObj = RaySensor.getHitObject()
we get what was hit and then ask:
if HitObj.Alive: # to find out if it can be damaged
on “True” we just say HitObj.Damage = HitObj.damage + 5

I know this is somekind of basic stuff, but i had a hard time getting it all to work and the explanation may leave lot’s of unanswered questions. I’ll be working on a tutorial explaing every line of code and how to let objects be affected by the impact (detruction and movement)…

Krabat


(Fred_Pyo) #3

Kool, I liked that! Thanx!