Hi,
I have a problem with the rotation of objects.
In my code I detect collisions from several small boxes with another big box.
After detecting collision I assign small box to big box (wrtReparentTo) and rotate big box using setHpr() method. As a result, the small boxes rotate together with the big box as a whole. And it works as it should.
def do_rotate(self, coll_entry):
pivot: NodePath = coll_entry.getIntoNodePath() # get big box
name = pivot.getName()
cubes = self.collided_cubes #list of small cubes NodePaths
children = pivot.getChildren()
children.wrtReparentTo(self.render)
pivot.clearTransform()
children.reparentTo(pivot)
for cubo in cubes:
cubo.wrtReparentTo(pivot) # reparent small boxes to big box
pivot.setHpr(self.mapping_sides[name]['rotation']*self.direction)
# rotate by Vec3 eg.: Vec3(0, 0, 90)
for cube in cubes:
cube: NodePath
cube.wrtReparentTo(self.scene)
children.reparentTo(self.render)
Now I’m trying to make the same rotation using hprInterval, so that all boxes rotate a given number of degrees in 0.3 seconds.
def do_rotate(self, coll_entry):
pivot: NodePath = coll_entry.getIntoNodePath() # get big box
name = pivot.getName()
cubes = self.collided_cubes #list of small cubes NodePaths
children = pivot.getChildren()
children.wrtReparentTo(self.render)
pivot.clearTransform()
children.reparentTo(pivot)
for cubo in cubes:
cubo.wrtReparentTo(pivot) # reparent small boxes to big box
# rotate by Vec3 eg.: Vec3(0, 0, 90)
hprInterval = pivot.hprInterval(0.3, self.mapping_sides[name]['rotation']*self.direction)
hprInterval.start()
for cube in cubes:
cube: NodePath
cube.wrtReparentTo(self.scene)
children.reparentTo(self.render)
But the second code causes only the big box to rotate.