Hi yall
I would like to ask what is the most effective way to stop an object moving
Example: B is moving to A, A shoots B, B stops moving to A ( passively, even B is supposed to be moving).
Thanks!
Hi yall
I would like to ask what is the most effective way to stop an object moving
Example: B is moving to A, A shoots B, B stops moving to A ( passively, even B is supposed to be moving).
Thanks!
You could use the suspend dynamics actuator (in the Edit Object actuator) if the objects are affected by physics. In addition to that, you should have a variable in each object which handles the state of the object to prevent it from doing certain things it’s not supposed to do at certain times.
I usually have a case where A can do things if a certain value is False or True.
if not own['frozen']:
do_movement()
The B can set A[‘frozen’] to True to stop it from moving.
It’s easy to get A from within B’s controlling code, either do it by name:
A = own.scene.objects['A']
or by property
A_list = [ob for ob in own.scene.objects if ob.get("A_property")]
if A_list:
A = A_list[0]
else:
A = None
Actually I use states, but you don’t have to. Simple True/False variables are fine.
thanks smoking mirror and mrputulips
but if the immobilzer suddenly disappears on the scene, how can i get the other one move again?
list = [ob for ob in own.scene.objects if ob.get("A_property")]
for obj in list:
if 'A_property' == True:
A_property = False
turns all frozen chars to unfrozen.
thanks cotax.
so there should be a script somewhere in the scene that checks if the immobilzer is on the scene right?
or you simply connect the script to immobilizers, so when he gets removed or dies etc you run the script to unfreeze all characters that are frozen.
so its like
if immobilzer[“health”] < 0:
unfreeze things
immobilizer.endObject()
right?
But is it 100% sure with 1 line of code? o.o
yes, thats is what i should do.
list = [ob for ob in own.scene.objects if ob.get("A_property")]
if own['health'] <= 0: # at 0 hp it's dead aswell people hate it when mobs/things stay alive with 0 hp ;)
for obj in list:
if obj['A_property'] == True:
obj['A_property'] = False
own.endObject()
thanks cotax ^.^
but don’t forget, if you use more then 1 immobilizer wrap it(whole script) into an function else they all would die at the same time. in a function the owner gets defined as an individual object.
def die_and_unfreeze():
list = [ob for ob in own.scene.objects if ob.get("A_property")]
if own['health'] <= 0: # at 0 hp it's dead aswell people hate it when mobs/things stay alive with 0 hp ;)
for obj in list:
if obj['A_property'] == True:
obj['A_property'] = False
own.endObject()
You can also add frozen things in to a list on B and then just run through the list to reactivate them if B dies. With that method you can also add a timer to each entity on the list so they can become unfrozen after a certain time instead of waiting for B to die.
If an object can be moving and not moving I suggest to use states:
e.g. active, inactive or moving, standing
This way you can switch the state to get the behavior you want. How you implement the states is totally up to you (it depends how you want to move your objects).
i guess own[“frozen”] is a good way.
restore the right state anyway should be responsability of the immobilizer i guess.
how about this parent/child replica?
(note the risk recursion)
EDIT: added the setters.
there is some mistake?
class Actor(KX_GameObject):
def __init__(self, gob):
self._immobilized = None
self._immobilizer = None
@property
def immobilizer(self):
if self._immobilizer and self.immobilizer.invalid:
self._immobilizer = None
return self._immobilizer
@property
def immobilized(self):
if self._immobilized and self._immobilized.invalid:
self._immobilized = None
return self._immobilized
def set_immobilizer(self, immobilizer):
assert isinstance(immobilizer,Actor)
self.remove_immobilizer()
self._immobilizer = immobilizer
immobilizer.set_immobilized(self)
def set_immobilized(self, immobilized):
assert isinstance(immobilized, Actor)
self.remove_immobilized()
self._immobilized = immobilized
def remove_immobilizer(self):
x = self.immobilizer
if x:
self._immobilizer = None
x.remove_immobilized()
def remove_immobilized(self):
x = self.immobilized
if x:
self._immobilized = None
x.remove_immobilizer()