animations upon collision

Hi I can make object disappear upon collision, which is kind of neat,
but I’d like to play an animation, instead of the object disappearing,
or changing color. If this is indeed possible, as I found only 9 search
matches in the forum with ‘animation AND collisions’ . :slight_smile:
About 7 of them were tiptoes ‘point click mouse’ topics.
C’mon!

Maybe someone can shed a little light on how to do this?
All I’ve found so far is the music box as an example,
and I’m not sure if it would be compatible.

On a side note, I love Panda3d! I made a little test and
loaded 20 1600 quad to tri poly 2048 textured and
normal mapped trees, and I still got 60.2 fps with only a little 2 second
loading ‘freezeup’ lag at the beginning, on my supercomputer.
Even microsoft was bragging about having halo 60 frames per second,
and i would be happy with 25, I think, as standard television
broadcast is only 24 fps…but I guess there’s a little more
going on in Halo 3 than running around in an orchard … Nevertheless!

let’s see if this scene could make you laugh :

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.showbase.DirectObject import DirectObject
from direct.interval.IntervalGlobal import *
from direct.actor import Actor
from direct.task import Task
import sys


class World(DirectObject):
  def __init__(self):
      self.accept('escape',sys.exit)
      base.cTrav = CollisionTraverser()
#       base.cTrav.showCollisions(render)
      self.cHandler = CollisionHandlerEvent()
      self.cHandler.setInPattern("collide-%in")
      self.cHandler.addInPattern("collide-%fn")
      collMASK=BitMask32.bit(1)
      collMASKoff=BitMask32.allOff()

      #load panda actor
      self.panda=Actor.Actor('panda-model',{'walk':'panda-walk4'})
      self.panda.reparentTo(render)
      self.panda.setScale(.01)
      pandaGeom=self.panda.find('**/+GeomNode')
      pandaGeom.setName('myPanda')
      pandaGeom.setCollideMask(collMASK)
      self.panda.accept('collide-myPanda', self.pandaHit,extraArgs=[self.panda])

      #load smiley
      self.smiley=loader.loadModel('smiley')
      self.smiley.reparentTo(render)
      self.smiley.setPos(0,20,2)
      self.smiley.setP(30)
      self.smiley.setScale(2)
      #create a collision solid for this model
      smileyC = self.smiley.attachCollisionSphere('smileyColl',0,0,0,1.1,collMASK,collMASKoff)
#       smileyC.show()
      base.cTrav.addCollider(smileyC, self.cHandler)
      self.moveAgain()
      self.accept('smileyMove',self.moveAgain)
      self.accept('collide-smileyColl',self.smileyHit)


      camera.setPos(30,-60,20)
      camera.lookAt(0,-20,0)
      mat=Mat4(camera.getMat())
      mat.invertInPlace()
      base.mouseInterfaceNode.setMat(mat)
      
      
  def moveAgain(self,t=0):
      pos1=self.smiley.getPos()+Point3(0,-1,.7)
      pos2=self.smiley.getPos()+Point3(0,-2,0)
      self.smileyPosIval = Sequence(
                  self.smiley.posInterval(.1,pos1),
                  self.smiley.posInterval(.1,pos2),
                  )
      self.smileyPosIval.setDoneEvent('smileyMove')
      self.smileyPosIval.start()
      print 'move'

  def pandaHit(self,actor,entry):
      pos1=actor.getPos()+Point3(0,-3,1.5)
      pos2=actor.getPos()+Point3(0,-4,0)
      posY=actor.getPos()+Point3(0,-10,0)
      pandaIval=Sequence(
                   Sequence(
                      actor.posHprInterval(.1,pos1,Vec3(0,15,0),blendType='easeOut'),
                      actor.posHprInterval(.1,pos2,Vec3(0,0,0),blendType='easeIn'),
                      ),
                   actor.posInterval(.5,posY,blendType='easeOut')
                   )
      pandaIval.setDoneEvent('stopActorMove')
      pandaIval.start()
      actor.acceptOnce('stopActorMove',actor.stop)
      actor.setPlayRate(10,'walk')
      actor.loop('walk')
      print 'hit'

  def smileyHit(self,entry=0):
      if entry:
         self.smileyPosIval.setDoneEvent('smileyHit')
         self.acceptOnce('smileyHit',self.smileyHit)
         return
      pos=self.smiley.getPos()+Point3(0,2,0)
      hIval=Sequence(
                  self.smiley.hprInterval(.08,Vec3(15,0,0),blendType='easeOut'),
                  self.smiley.hprInterval(.08,Vec3(-15,0,0),blendType='easeOut'),
                  )
      smileyHitIval = Sequence(
                  self.smiley.posHprInterval(.1,pos,hpr=Vec3(0,0,0),blendType='easeIn'),
                  Wait(.2),
                  hIval, hIval,  hIval, hIval,
                  self.smiley.hprInterval(1.5,Vec3(0,30,0),blendType='easeOut'),
                  )
      smileyHitIval.setDoneEvent('smileyMove')
      smileyHitIval.start()

  

World()
run()

ynjh_jo, smartest man on the planet!
I was saying to myself “maybe I can do it ‘boxing robots style’,
with a one percent chance of a hit or something.”
There are no collision spheres involved with the ‘boxing robots’,
so I would have never gotten that to work!
Now I can get back to work though,
(after a weeks bed rest that is)
because that would have really sucked, that ‘boxing robots style’!
You even coded for the panda to stop,
instead of looping forever, the walking! :smiley: