so im trying to make my car to stay in the start of the screen while moving every thing else to the left but im not ver succesfull at that. my car dont need any inputs from a player it always run with the same speed. here is what ive maid so far -
def update(dt):
global car_x
global CanIStart
space.step(0.02)
for shape in space.shapes:
if(shape.id == 1):
carRunNow = int(shape.body.position[0]) - car_x
car_x = int(shape.body.position[0])
CanIStart = True
if(CanIStart):
for shape in space.shapes:
if(shape.id == 15):
space.remove(shape)
shape.body.position = (int(shape.body.position.x)-carRunNow, int(shape.body.position.y))
space.add(shape)
Here is my road code -
def make_road(space, size, posOne, run):
if(run == 10):
part_shape = pymunk.Segment(space.static_body, (0, 150), (300, 150), 2)
part_shape.body.position = 0, 0 # Set the position of the body
part_shape.elasticity = 0.62
part_shape.friction = 0.62
part_shape.id = 15
space.add(part_shape)
make_road(space, size, (300, 150), run-1)
return
elif(run > 0):
modifier = random.randint(-80,80)
while(posOne[1] + modifier < 0):
modifier = random.randint(-80,80)
part_shape = pymunk.Segment(space.static_body, posOne, (posOne[0] + size, posOne[1] + modifier), 2)
part_shape.elasticity = 0.62
part_shape.friction = 0.62
part_shape.id = 15
space.add(part_shape)
print(posOne)
make_road(space, size, (posOne[0] + size, posOne[1] + modifier), run - 1)
return
else:
return
the shape id 15 is the road. this code makes some problams - the first one the car's wheels go through the road and the second is that the movment isnt very smoothly.
thanks for the help :)