Graphic model don't move in the right direction

Hi…

Im creating a car game. Below are some source code from a class called Rally.py In there i have some methods for driving the car.

My problem is that when i press the up-arrow the car is moving to the left. This is handled by the def doPhysics()- method. I just dont understand why it doesn’t moves straight ahead?

Any ideas, here is the code?


import vehicle
import Factory
from direct.actor import Actor
from direct.interval.IntervalGlobal import *

class Rally(vehicle.Vehicle,Actor.Actor):
	"A Jeep Class"
	physics =""
	#Some constants for the program
	ACCEL = 70         #Acceleration in ft/sec/sec
	MAX_SPEED = 5      #Max speed in ft/sec
	MAX_SPEED_SQ = MAX_SPEED ** 2  #Squared to make it easier to use lengthSquared
																	#Instead of length
	throttle  =0                           
	
	def __init__(self):
		print "Loading a rallycar!"
		Actor.Actor.__init__(self)
		#vehicle.Vehicle.__init__(self)
		self.carMove= Sequence()
		self.loadModel("../models/rallyCar/rallyCar")
		# Load animation
		self.setScale(0.04)
		self.setPos(0,0,0)
		self.setH(11)
		self.speed = 0 # current speed                     
		self.maxSpeed = 60.0 # maximum speed       
		self.acceleration = 0.3 # acceleration rate
			
	def drive(self):
		if self.throttle<self.maxSpeed:
			self.throttle += self.acceleration
		print self.throttle
			
	def right(self):
		print "right"
	
	def left(self):
		print "left"
	
	def reverse(self):
		if self.throttle > 0:
			self.throttle -= self.acceleration
	
	def bindPhysics(self,phys):
		self.physics=phys
		self.reparentTo(phys)
	
	def bindCamera(self,camera):
		camera.reparentTo(self)
		camera.setPos(160, 0,60)
		camera.setHpr(90,348,0)

	def doPhysics(self,task):
		dist = self.throttle/10 
		print dist
		print self.getH()          								
		angle = self.getH()*math.pi/180.0					
		dx = dist*math.sin(angle)
		dy = dist*-math.cos(angle)
		self.setPos(self.getX()+dx,self.getY()+dy,self.getZ())		
		return Task.cont

def createRally():
    return Rally()

Factory.Instance.Register("Rally",createRally)

If its just moving slightly to the left, its because you used self.setH(11). Delete that line and it should go straight forward. If you mean its moving perpendicular to that setH() command, it could be something else.

Your camera is rotated 90 degrees to the right. Therefore, “forward” from the view of your car is left from the cameras point of view.

Hello,

Totally out of topic, i’m very interrested by your line.

Factory.Instance.Register(“Rally”,createRally)

from what i guess, Factory is your world object creation class.
It’s a singleton stored in Factory.instance.

This singleton is able to create any class , provided the class string, here “Rally” and a create method provided.

How do you pass a method as argument in this case?
Would you mind showing me the Register code and the Object creation code
of your factory Instance?

I’m doing on fly object creation in my system but by interpreting on fly generated loading code right now so…

as a note, anything in python can be passed (and stored) as an argument.


class myClass(object):
     def __init__(self,callback, callbackArgs):
          self.callback=callback
          self.args=callbackArgs
     def triggerCallBack(self):
          self.callback(*self.args)

def myCallback(val1, val2):
     print "called back with", val1, "and", val2

test=myClass(myCallback,[56,"Hello"])
test.triggerCallBack()

Note: * in python before a list means (if I am inside a function call, take the following list and pass it out as a set of arguments to the function.