Graphic model don't move in the right direction


Im creating a car game. Below are some source code from a class called 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 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!"
		self.carMove= Sequence()
		# Load animation
		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):
	def bindCamera(self,camera):
		camera.setPos(160, 0,60)

	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)
		return Task.cont

def createRally():
    return Rally()


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.


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


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):
     def triggerCallBack(self):

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


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.