Collision of two boxes
I'm trying to figure out how to improve some old code by using classes. The current situation is that I try to collide two boxes (box1 and box2) and after collision, box2 should change color. Now I can get this working by calling e.obj1.color() in the collide function, but I would like to use the change_color() function I defined in the class. My question is why e.obj1.change_color() doesn't work. As I see it, e.obj1 refers to box2, which is an instance of the class make_box(). But when I print e.obj1, I get something different than when I print box2, indicating that they are not the same. So I think the problem is in how the collide function works, but I don't know how to get e.obj1 to work with the method I defined for box2. See below for my code. The keys w, a, s, d move box1 around, to be able to collide with box2.
Code:
import viz |
As your print statements point out, e.obj1 is not box2. e.obj1 is the box.wrl VizNode object you created in the make_box constructor.
The solution is to have make_box inherent from VizNode. This Vizard help page shows how to do that: http://www.worldviz.com/vizhelp/Stru...rd_scripts.htm It also has a link to an object oriented Python tutorial I suggest you check out: http://www.freenetpages.co.uk/hp/ala...d/tutclass.htm |
Thanks for your reply! Having make_box inheret from VizNode did the trick. The link to the object oriented Python tutorial was helpful as well.
|
Glad to help. Especially to you, who is wise to invest in improving your code.
|
All times are GMT -7. The time now is 10:56 PM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC