Let's add a PythonTag
to our CollisionNodes
so we can print out the names of the cycles when they collide.
In the
setupCollisions
method of ourCycle
class, add the following line of code right after we createself.shieldCN
:self.shieldCN.setPythonTag("owner", self)
In the
bump
method, replace theprint
statement we have with the following:print(entry.getFromNodePath().getPythonTag("owner").name) print("has bumped into:") print(entry.getIntoNodePath().getPythonTag("owner").name) print("")
Save the file as
CycleClass_04.py
.Modify
WorldClass_03.py
to importCycleClass_04.py
instead ofCycleClass_03.py
. Then, save it asWorldClass_04.py
and run it from the command prompt. Make sure to watch the command prompt when the cycles collide and you see something similar to the following screenshot: