I found a script on the forum,
Which activates the dynamics of objects in a certain area to the impact of a sphere.
But sometimes objects lose their dymanics after a certain time and I can not solve this problem.
I would also like to activate the dynamics of the objects above those in the impact area.
I tried with a ray sensor, but I’m just starting to learn python (just for this script)
and I can not get it
I solved the first problem, and I think I found the solution for the second.
But I can not put it on python.
I use a radius on my sphere,
which removes the parent of the bricks lying inside, and activates their ray sensor
I would like that the bricks hit by a ray sensor also activate their ray sensor,
in order to create a chain reaction
Blend. : Mon script4.blend (1.28 MB)
(Space to shoot, “q” and “d” to move)
Here is my code:
import bge
from bge import render
from bge import logic as gl
def bullet(cont):
own = cont.owner
collision = cont.sensors["Collision"]
message = cont.actuators["Action"]
radius = own.get('radius', 3)
if collision.positive and not "r" in own:
bge.logic.bullet = (collision.hitObject, radius)
cont.activate(message)
own["r"] = 1
def brick(cont):
own = cont.owner #own.suspendDynamics()
message = cont.sensors[“Message”]
if message.positive:
hitObject, radius = bge.logic.bullet
distance = own.getDistanceTo(hitObject)
#print(dir(own))
if distance < radius:
ray = cont.sensors["Ray"]
if ray.positive:
First there’s errors in your script. You can see em in the console.
If you’re on Windows it’s Window -> Toggle System Console
Python script error - object 'Cube.132', controller 'Python':
Traceback (most recent call last):
File "/home/user/Downloads/Mon script4.blend/Scripts.py", line 36, in brick
UnboundLocalError: local variable 'ray' referenced before assignment
The indentation at line 36 needs to be 1 level deeper.
AttributeError: module 'Scripts' has no attribute 'main'
Python controller found the module but could not access the function - object 'Cube.110', controller 'Python.001':
There’s no main function in the script. I assume that controller is redundant anyway.
Traceback (most recent call last):
File "/home/user/Downloads/Mon script4.blend/Scripts.py", line 40, in brick
AttributeError: attribute 'hitObject' of 'KX_RaySensor' objects is not writable
Thank you very much !! It’s perfect, and I understand how it works!
Except for the “logic states”
But I would see tomorrow, I need to sleep ^^
thanks again