[SOLVED]My train does not turn

I used to move the train by mopath .

It‘s my code:

#!/usr/bin/pythonfrom panda3d.bullet import BulletTriangleMesh
#coding:utf8

from pandac.PandaModules import loadPrcFileData
loadPrcFileData('', 'bullet-additional-damping 1')
loadPrcFileData('', 'egg-load-old-curves 1')

from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.directutil import Mopath
from direct.interval.MopathInterval import *

from panda3d.core import Vec3
from panda3d.core import TransformState
from panda3d.core import Point3

class MyApp(ShowBase):
	def __init__(self):
		ShowBase.__init__(self)

		g = loader.loadModel('rail')
		g.reparentTo(render)

		#移动摄像机
		self.disableMouse()
		
		taskMgr.add(self.task, 'mainTask')

		train = loader.loadModel('train')
		train.reparentTo(render)

		#########################################################
		rail = Mopath.Mopath()
		rail.loadFile('path')
		
		railInterval = MopathInterval(rail, train, name='train', duration=100)
		railInterval.loop()
		#########################################################

		camera.reparentTo(train)
		camera.setPos(0,-120,40)
		camera.setHpr(0,-15,0)

	def task(self, task):

		return task.again

app = MyApp()
app.run()

and this is full file:
ubuntuone.com/0ps4SWdJgXFxQFBGY1J9g7
It’s my blender file:


video:
tudou.com/programs/view/4ARZY-eLq5I/
But the train Neither turn nor travel along the rails.

Well, the train and rail models made the program crash for me, so something is up there.

Anyway - I think your motion path egg file isn’t quite right.

I replaced yours with a different one, and the train moved ok. So the code itself works.

I used wezu’s egg file from here:
[[SOLVED] Mopath: Mopath has no curves)

I used wezu’s egg file too, and change my code:

   def task(self, task):
      print self.train.getHpr()
      print self.train.getPos()
      return task.again

Then the code output:

...
...
...
LPoint3f(0.124703, 0.262276, 0.386979)
LVecBase3f(0, 0, 0)
LPoint3f(0.124943, 0.262388, 0.387331)
LVecBase3f(0, 0, 0)
LPoint3f(0.125191, 0.262504, 0.387695)
LVecBase3f(0, 0, 0)
LPoint3f(0.125423, 0.262612, 0.388035)
LVecBase3f(0, 0, 0)
LPoint3f(0.125697, 0.262738, 0.388435)
LVecBase3f(0, 0, 0)
LPoint3f(0.125909, 0.262836, 0.388745)
LVecBase3f(0, 0, 0)
LPoint3f(0.126152, 0.262948, 0.3891)
LVecBase3f(0, 0, 0)
LPoint3f(0.126382, 0.263053, 0.389435)
LVecBase3f(0, 0, 0)
LPoint3f(0.126631, 0.263167, 0.389798)
LVecBase3f(0, 0, 0)
LPoint3f(0.126874, 0.263277, 0.390151)
LVecBase3f(0, 0, 0)
LPoint3f(0.127128, 0.263393, 0.390521)
LVecBase3f(0, 0, 0)
LPoint3f(0.127368, 0.263501, 0.390868)
LVecBase3f(0, 0, 0)
...
...
...

The hpr always are (0,0,0)

Try:

rail.fFaceForward = 1

It should force your train to look in the direction it is travelling.

I tried with smiley, but it was going in reverse, so to turn it around I did:

train.setH(180)
train.flattenLight()

Thank you ! The code is now very well.