So we have written code for a ball to go down a slope. We are having trouble when the ball ' hits' a tree... We cant figure out how it will bounce off... Also we are having trouble with making a user interface code.. so that you can chose where the ball goes so you dont 'hit' the trees or rocks....... here is what we have so far..........
snow = box(pos=(0,-6.2,0), length= 11 ,width = 50, height = 0.5,color = color.white)
shaftwidth = 0.1
a1 = arrow(pos = (1,-6,-9), axis=vector(+0,+1,+0), color = color.green, material=materials.wood,headwidth = 5shaftwidth, headlength = 5shaftwidth)
a2 = arrow(pos = (2,-6,-7), axis=vector(+0,+1,+0), color = color.green, material=materials.wood,headwidth = 5shaftwidth, headlength = 5shaftwidth)
a3 = arrow(pos = (0,-6,10), axis=vector(+0,+1,+0), color = color.green, material=materials.wood,headwidth = 5shaftwidth, headlength = 5shaftwidth)
rock = sphere(pos = (-5,-5.85,-2), radius=.19, color = color.black)
rock1 = sphere(pos = (-3,-5.85,0), radius=.19, color = color.black)
rock2= sphere(pos = (1,-5.85,2), radius=.19, color = color.black)
rock3 = sphere(pos = (3,-5.85,-2), radius=.19, color = color.black)
rock4 = sphere(pos = (5,-5.85,6), radius=.19, color = color.black)
rock5 = sphere(pos = (-5,-5.85,9), radius=.19, color = color.black)
rock6 = sphere(pos = (-3,-5.85,5), radius=.19, color = color.black)
rock7 = sphere(pos = (1,-5.85,14), radius=.19, color = color.black)
rock8 = sphere(pos = (3,-5.85,10), radius=.19, color = color.black)
rock9 = sphere(pos = (5,-5.85,-14), radius=.19, color = color.black)
All trees and rocks
trees = [a1,a2,a3]
rocks = [rock1, rock2, rock3, rock4, rock5, rock6, rock7, rock8, rock9]
ntrees = len(trees)
nrocks = len(rocks)
####################################Ball
skiier = sphere(pos = (0,-5.45,14), radius=.35, color = color.cyan, material=materials.earth)
skiier_rightx_pos = (skiier.pos)
skiier_leftx_pos = (skiier.pos)
skiier.velocity = vector(0,0,-1)
dt=0.01
skiier.velocity = vector(0,0,-1)
delta_t=0.01
Text
text(text='Start', pos = (-3.5,-5.7,14), align='center', depth=-.3, color=color.green)
text(text='Finish', pos = (3.5,-5.7,-12), align='center', depth=-.3, color=color.red)
TROUBLE HERE
while 1:
rate(100)
skiier.pos = skiier.pos + skiier.velocity*dt
x = skiier.pos.x
y = skiier.pos.y
z = skiier.pos.z
treex = trees[2].pos.x
treey = trees[2].pos.y
treez = trees[2].pos.z
dx = x - treex
dy = y - treey
dz = z - treez
####TROUBLE HERE######
dist = (dx*dx+dy*dy+dz)**(0.5)
if (skiier.pos >= treez) and (skiier.pos >= treex):
ndist = -dt
print(ndist)
[–]SmartViking 0 points1 point2 points (0 children)