For this exercise, we won't be using our game. Instead, we're going to start with a blank document and make a quick little collision system to see things in action before we start on the more complicated collisions in the game.
Create a blank document in Notepad++ and save it as
chp06_01.py
.Add this block of code to the beginning of the file:
import direct.directbase.DirectStart from direct.showbase.DirectObject import DirectObject from pandac.PandaModules import * class World(DirectObject): def __init__(self):
Right after that, type in these lines:
self.colNode1 = CollisionNode("colNode1") colSphere1 = CollisionSphere(4.1,30,0,1) self.colNode1.addSolid(colSphere1) self.colNP1 = render.attachNewNode(self.colNode1) self.colNP1.show()
Now, copy and paste the block of code from step 3, and modify it to look like this:
self.colNode2 = CollisionNode("colNode2") colSphere2 = CollisionSphere(0,30,0,1) self.colNode2.addSolid...