projectile sequence

Hello there,

Am attempting to make a spear hit a character and cannot figure out how to stop the projectileInterval sequence I have create when a hit is generated:

spearThrow = ProjectileInterval(self.spear,startPos = self.spear.getPos(),startVel = Point3(x,0,z),duration = 1) #defines projectile force and trajectory
spearGo = Sequence(spearThrow) #interval to sequence
spearGo.start() #begins the spearGo sequence

When a collision is made i want to attach the spear to the animated death of a character so it remains stuck through the character.

I think I can just attach the spear node to the character but I think it wont let me at the time of the collision as the sequence is still playing.

Is there anyway round this? I believe I can do it with a task but I like the spear is effected by gravity in the projectileInterval function.

Any help would be greatly appreciated.

you can pause the sequence, then do whatever you want with the spear, i think

Yeah, try something like this when a collision occurred:

spearGo.pause()
yourSpear.wrtReparentTo(collisionentry.getIntoNodePath())

or something like that.

cheers for the input,

my projectile interval is in a function where the force can be defined:

def setObjectForce(self, x, z):
if (self.began == False):
spearThrow = …
…spearGo.start()

collision event takes place here:

def collide(self, collEntry):
self.gladE.removeNode() #remove run animation
self.enemyDeath(collEntry) #begin death seq1
print ‘Hit’

def enemyDeath(self, collEntry):
#Load and play death animation
self.gladEDeath = Actor.Actor(“Game\spear\gladEnDeath”, {“GladiatorDeath”:“Game\spear\gladEnDeath”})
self.gladEDeath.reparentTo(render)
self.gladEDeath.setPos(80,250,-10)
self.gladEDeath.setH(-90)
self.gladEDeath.setScale(1.5,1.5,1.5)
self.gladEDeath.play(‘GladiatorDeath’)

I want to stop the spear projectile so i need to call the setObjectForce function right? self.setObjectForce().spearGo.pause()? But then i need to input arguments.

Have I gone about this the wrong way altogether? I’m pretty new at this and am just trying lots of different methods until I get the required results rather than probably doing it the correct way.

Many thanks once again

I got it to work, had nothing to do with pausing the sequence in the end, just needed to get my node parenting correct, thanks for the help:

def enemyDeath(self, collEntry):
self.hitpoint = self.gladEDeath.exposeJoint(None, ‘modelRoot’, ‘Chest’)#to attach the spear to bone manipulation of specific bone

collEntry.getIntoNodePath().wrtReparentTo(self.hitpoint)
collEntry.getFromNodePath().getParent().getParent().wrtReparentTo(collEntry.getIntoNodePath())

self.gladE.hide()
self.gladEDeath.play(‘GladiatorDeath’)

****I could only get working with exposeJoint, spear wouldnt follow the animation otherwise, why is this?

Ok this was working fine but I now get a:
detected attempt to create a cycle in the scen graph

I dont know why as I havent altered any of the collision script code. Does anyone know why this error occurs? The code that generates the error is:

def collisions(self):
     
    #sets up traverser     base.cTrav = CollisionTraverser()
    
    #initialise handler of collision
    lifter = CollisionHandlerFloor()
    self.collHandEvent=CollisionHandlerEvent()
    self.collHandEvent.addInPattern('%fn-into-%in')
    self.collHandEvent.addOutPattern('outof-%in')
    
    #Sets up collision geometry to object in scene
    colSpear = CollisionSphere(0, 0, 20, 1) #type of collision geo is tube, set Pos in line with spear
    colSpearNodePath = self.spear.attachNewNode(CollisionNode('spearCol')) #sets up node path of collision (attached to spear) 
    colSpearNodePath.node().addSolid(colSpear) #attachs col geo to node path
    colSpearNodePath.show() #show the col geo
        
    colSphere = CollisionSphere(0,0,0,5)
    colSphereNodePath = self.chest.attachNewNode(CollisionNode('gladECol'))
    colSphereNodePath.node().addSolid(colSphere)
    colSphereNodePath.show()
    #colSphereNodePath.setPos(0,0,20)
    
     #add this object to the traverser
    base.cTrav .addCollider(colSpearNodePath , self.collHandEvent)
        
    #accept the events sent by the collisions
    self.accept('spearCol' + '-into-' + 'gladECol', self.enemyDeath)
    
    
    #Load and play death animation
  def enemyDeath(self, collEntry):
    self.gladEDeath = Actor.Actor("Game\spear\gladEnDeath", {"GladiatorDeath":"Game\spear\gladEnDeath"}) #Load DeathAnimation
    self.gladEDeath.reparentTo(render)  #To render
    self.gladEDeath.setPos(80,0,-10)  #Set Pos
    self.gladEDeath.setH(-90)   #Set Rot
    self.hitpoint = self.gladEDeath.exposeJoint(None, 'modelRoot', 'Chest')     #To allow manipulation of specific bone, ***required for spear to follow animation,WHY?****
    collEntry.getIntoNodePath().wrtReparentTo(self.hitpoint)    #Attaches gladE's collision solid to hitpoint (gladEDeath chestBone)
    collEntry.getFromNodePath().getParent().getParent().reparentTo(self.hitpoint)      #Attaches spear to hitpoint
    self.gladEDeath.play('GladiatorDeath')
    self.gladE.hide()

I cant understand as this code ran fine before and did exactly what I wanted it to do. I have added code that effects the trajectory of the spear. I have since deleted all this new code but the error still generates. Feel like I cant make progress until this is sorted but cant get my head around it. any ideas?