Access the Sensor of another object in BGE

(blenderaptor) #1

Hi ,

Im’ using state actuators to use a delay sensor in order to shift an action in time. I want to modify the delay value at will.

I want to parameter the .delay value of a delay sensor of another object in another state. I dont really know how i can change its value as - if i connect a controller to it ; that controller will be triggered by that delay sensor … so not possible to change the .delay value in the first place … lol. It’s possible to change sensors value even if its not connected to a python controller ? In other words, change its value from another python controller (even from another object and another state ) ?

Or, I can put an “alwyas” sensor beside the delay sensor so it can fix the delay value at the first frame after the state is setted ?

0 Likes

(blenderaptor) #2

okey … found the answer.

the_object.sensors[n].delay = 3652124

with n, the position of the sensor (or simply its ‘name’ ) in the list of sensors.

1 Like

(BluePrintRandom) #3

scene = bge.logic.getSceneList()[‘SceneName’]

target = scene.objects[‘TargetName’]

sensor = target.sensors[‘SensorName’]

:smiley:
this way we can access objects even across scenes.

0 Likes

(Monster) #4

May I ask why you think you need this?

This demand introduce quite a ot of complexityt to your logic. One object needs to know the exact structure of another object. If you change on of them the behavior will mostlikely not be as you expect it to be.

0 Likes

(blenderaptor) #5

I need this because object A needs to be self-triggered with a delay. Object B is in charge of that, via changing states, but Object A has to set the delay value of Object B. Object B , triggered by the delay sensor, cannot modify that delay value.

0 Likes

(Monster) #6

In other words:

Object A needs to sense - X frames after object B changes it’s state?

0 Likes

(blenderaptor) #7

yes. set and set-back states is good way to re-initiate a delay sensor

0 Likes

(Monster) #8

What is the meaning of the event?

I mean when object B switches the state the meaning could be: “Object B switched state”.

The event you want is later. Currently I see it as afollowup event.
Why you need this delay?
What object should determine the length of the delay (on what input)?

0 Likes

(blenderaptor) #9

When object A sends a punch to C it triggers B (changing state). After a delay in the new state , B triggers C to make it play the “hitted” action… (the punch is delivered) So, A has to inform B the value of the delay. And there’s no reasons that A and B have to be connected (even more if B is not on the same state at that moment)

I prefer to use object B rather than 1 of the 2 others and make it deal all the matters of timing.

0 Likes

(Monster) #10

So you still have two objects? (A and B or C)?

Object A has the state “punching” and other states.
Object A enters state punching (I guess it animates a punch animation)

After a while in state punching object A tells object B/C it gets hit?

0 Likes

(blenderaptor) #11

i have 3 objects. A, C : 2 characters . B, an empty . Why you ask all this ? :smiley:

0 Likes

(Monster) #12

I want to understand the relationship between the objects.

Typically I would not want to relay on a sensor of another object. The reasons are simply:
What if that other object does not exist? What if I redesigned the object and removed the sensor? What if I renamed the sensor, because I didn’t noticed it is used somewhere else?

There are situations that only a specific object can measure a certain condition e.g. a phyiscs object can sense a collision. An armature can’t. So if I want to start something on the armature after the collision happened, the armature alone can’t sense that.

Your situation sounds like that. But you have more requirements (the delay). So I was thinking about what object should deal with the delay. To get an answer I would like to understand the motivation behind it. This knowledge shows the proposed solution is really a solution and does not just solve a local issue. It can also show alternative solutions.

0 Likes