taskMgr and ActorNode

Hello there, I’d first like to start out by saying that my name Lawrence Howard, I am a BTEC National Diploma student in Games Design and Devlopment. I have good knowledge and understanding of the LUA code language, and Python is something I have often overlooked.

I am quite quick to understand things, and I have run into a bit of a snag with my code.

I have set up my scene, with an ActorNode that is being pushed forward, and I have a task that should be putting the camera at x,x,x position.

The camera gets put into position as the task says - howvever it seems to either not repeat - or the co-ordinates do not change. The model does move along however. Am I missing something here?

On a side note - I’m a little confused over the force - I’m fairly sure that its being applied to every node - how do I apply it exclusively to my pinkpiggy.

Apologies for all the questions, but thanks in advance for any help offered.

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.task import Task
from direct.actor import Actor
import math
from pandac.PandaModules import *
from direct.gui.OnscreenText import OnscreenText



# Function to put title on the screen.
def addTitle(text):
    return OnscreenText(text=text, style=1, fg=(1,1,1,1),
                   pos=(1.3,-0.95), align=TextNode.ARight, scale = .07)



class PinkPiggy(DirectObject):
	def __init__(self):
     
	 self.keyMap = {"left":0, "right":0, "forward":0, "cam-left":0, "cam-right":0}
	 base.disableMouse()
	 base.enableParticles()
	 self.title = addTitle("Mini Pig Racing")
   
     #Load the panda actor, and loop its animation
	 Node=NodePath(PandaNode("PhysicsNode"))
	 Node.reparentTo(render)
	 self.pinkpiggy=loader.loadModel("mrpiggyrun/pink_piggy")
	 self.an=ActorNode("pinkpiggy-physics")
	 self.anp=Node.attachNewNode(self.an)
	 base.physicsMgr.attachPhysicalNode(self.an)
	 self.pinkpiggy.reparentTo(self.anp)
	 self.pinkpiggy.setScale(0.05,0.05,0.05)
	 self.pinkpiggy.setPos(-8.75,0.7,0.62)
	 self.pinkpiggy.setH(90)
	 forwardFN=ForceNode('world-forces')
	 forwardFNP=render.attachNewNode(forwardFN)
	 forwardForce=LinearVectorForce(0.1,0,0) #gravity acceleration
	 forwardFN.addForce(forwardForce)
	 base.physicsMgr.addLinearForce(forwardForce)
	 
	 taskMgr.add(self.cam,"camTask")
	 taskMgr.add(self.pigpos,"pigposTask")
      
     #Load the first environment model
	 self.environ = loader.loadModel("mrpiggyrun/sky")
	 self.environ.reparentTo(render)
	 self.environ.setScale(3,1,1)
	 self.environ.setPos(0,0,0)
	  
	 self.pinkpiggyx = self.pinkpiggy.getX()
	 self.pinkpiggyy = self.pinkpiggy.getY()
	 self.pinkpiggyz = self.pinkpiggy.getZ()

	def pigpos(self, task):
		self.pinkpiggyx = self.pinkpiggy.getX()
		self.pinkpiggyy = self.pinkpiggy.getY()
		self.pinkpiggyz = self.pinkpiggy.getZ()
		return Task.cont
	def cam(self, task):
		base.camera.setPos(self.pinkpiggyx-1.75,self.pinkpiggyy,self.pinkpiggyz+0.4)
		base.camera.setH(self.pinkpiggy.getH()-180)
		return Task.cont

p = PinkPiggy()

run()

EDIT: Succesfully applied forces to specified objects only =] just need a hand with the taskMgr stuff now.

So nobody can figure out what is up with it? :cry:

Hmm, I’m not sure why you need to use two tasks to do this but it is a mystery why its not working. Could you try putting different print statements in each of your tasks?

The easier way to do achieve what you want to do is to remove the pigpos task and change the cam function to the following:

def cam(self, task):
    base.camera.setPos(self.pinkpiggy, -1.75, 0, 0.4)
    base.camera.setH(self.pinkpiggy.getH()-180)
    return Task.cont

The new camera.setPos is now relative to the self.pinkpiggy NodePath.

Hooray! Thank you so much ZeroByte!

I think I must have been linking something entirely wrong >.<

Until my next mistake, cya next time :slight_smile: