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)