• I Move Bugfix
    3 replies, posted
Picked up on a bug in the code I released with my I Move contraption. This fix won't make any difference to the I Move itself (hence why there is no actual contraption here), but for those of you wishing to make your own versions, it will. The ride height variable wasn't read from before, but now it is. [code] @name Walking Chip MkIV @inputs Left:entity Right:entity W A S D R Space Active @outputs Jump Effect Hide @persist Foot_pos_array:array Heading Stage Offset Speed Foot:entity Sensativity Host:entity @persist Angle:angle Foot_dest_rot Foot_final_rot Foot_rot:angle Speed_rot On Stride Foot_lift Foot_fall Delay @persist Dest:vector Foot_final_pos:vector Foot_dest_pos:vector Foot_force:vector Offset_static @persist Left_rot:angle Right_rot:angle Dest_l:vector Dest_r:vector Jet Jump_jet Ride_height if (duped()) { reset() } if (first()) { #insert *On before the final brackets on lines 124 and 126 to make the robot collapse when not in use On=0 Hide=1 Host=entity():isConstrainedTo() Heading=Host:angles():yaw() Foot_pos_array=array() Foot=Right Stage=0 Jump=100 soundPlay(6,0,"ambient/levels/canals/dam_water_loop2.wav") soundVolume(6,0) #the 12 lines below are constants that you can alter to allow for different sized walking bases Delay=10 #how many 10s of millieseconds to let the foot settle after reaching its final destination before moving the other foot Foot_lift=14 #how far below the pelvis to lift the foot up to Foot_fall=7.5 #how fast the foot falls to its final position Stride=48 #how far forwards from the pelvis to pus the foot before letting it fall Speed=5 #how many units to move the foot every 10 milliseconds Sensativity=1 #how many degrees every 10 millieseconds to alter the heading by Offset=12 #how far to the side the feet are from the pelvis Ride_height=50 #how high above the point between the feet that the pelvis should be Jump_jet=10 #how far up from the normal position the feet will be when jumping/jetting (and twice that of how far forwads they will be) Left:setMass(250) #mass of the left foot (this should be left alone under most but not all circumstances) Right:setMass(250) #mass of the right foot (this should be left alone under most but not all circumstances) Host:setMass(750) #mass of the pelvis (this should be left alone under most but not all circumstances) Offset_static=Offset interval(10) } if (clk()) { if (Jump<100 & Space!=1) { Jump+=0.125 } if (Space & Jump>1) { Effect=min(floor(Jump),1) soundVolume(6,1) Jump-=1 W=0 S=W Stage=S soundStop(1) soundStop(2) soundStop(3) Dest_r=(Host:pos()+Host:forward()*(Jet/10)+Host:right()*(Offset_static*1.5)+Host:up()*(Jet-Ride_height))-Right:pos() Right:applyForce((($Dest_r*20)+(Dest_r*4))*Right:mass()) Dest_l=(Host:pos()+Host:forward()*(Jet/10)+Host:right()*(0-(Offset_static*1.5))+Host:up()*(Jet-Ride_height))-Left:pos() Left:applyForce((($Dest_l*20)+(Dest_l*4))*Left:mass()) if (Jet<Jump_jet) { Jet+=1 } Foot_yaw=Left:angles():yaw()-(Heading+15) if (Foot_yaw>180) {Foot_yaw-=360} if (Foot_yaw<-180) {Foot_yaw+=360} Left_rot=Left:angles():setYaw(Foot_yaw):setPitch(Left:angles():pitch()+30) Left:applyAngForce(($Left_rot*10+Left_rot*2)*Left:mass()*-1) Foot_yaw=Right:angles():yaw()-(Heading-15) if (Foot_yaw>180) {Foot_yaw-=360} if (Foot_yaw<-180) {Foot_yaw+=360} Right_rot=Right:angles():setYaw(Foot_yaw):setPitch(Right:angles():pitch()+30) Right:applyAngForce(($Right_rot*10+Right_rot*2)*Right:mass()*-1) } elseif (Jet>0) { Jet-=1 Effect=0 soundVolume(6,0) } if (Active!=On) { if (Active==1) { Hide=0 soundPlay(4,0,"npc/roller/remote_yes.wav") Heading=Host:angles():yaw() } else { Hide=1 Stage=0 soundStop(1) soundStop(2) soundStop(3) soundPlay(5,0,"npc/roller/code2.wav") } On=Active } Heading+=(A-D)*Sensativity if (Heading>360) {Heading-=360} if (Heading<0) {Heading+=360} if (R==1) { Stage=1 } Yaw=Host:angles():yaw()-Heading if (Yaw>180) {Yaw=0-(360-Yaw)} if (Yaw<-180) {Yaw=360+Yaw} Angle=Host:angles():setYaw(Yaw) Host:applyAngForce(($Angle*20+Angle*4)*Host:mass()*-1) Dest=(mix(Left:pos(),Right:pos(),0.5)+vec(0,0,Ride_height))-Host:pos() Host:applyForce((($Dest*20)+(Dest*4))*Host:mass()) if (W!=S & Stage==0 & Foot:vel():length()<2.5) { Stage=1 } if (Stage==1) { Foot_pos_array:insertVector(1,Foot:pos()+vec(0,0,Foot:radius()*3)) Foot_pos_array:insertVector(2,Host:pos()+Host:up()*(0-Foot_lift)+Host:right()*Offset) Foot_pos_array:insertVector(3,Foot_pos_array[2,vector]+Host:forward()*((W-S)*Stride)) Foot_final_rot=Heading Foot_dest_rot=Foot:angles():yaw() Foot_dest_pos=Foot:pos() soundPlay(1,0,"vehicles/tank_turret_start1.wav") soundVolume(1,0.375) Stage+=1 } elseif (Stage==2 | Stage==4 | Stage==6) { Foot_final_pos=Foot_pos_array[Stage/2,vector] Stage+=1 } elseif (Stage==3 | Stage==5 | Stage==7) { soundPlay(2,0,"vehicles/tank_turret_loop1.wav") soundVolume(2,0.375) if (Foot_dest_pos:distance(Foot_final_pos)>Speed) { Foot_dest_pos+=((Foot_final_pos-Foot_dest_pos):normalized()*Speed) } else { Stage+=1 } Foot_force=Foot_dest_pos-Foot:pos() Foot:applyForce((($Foot_force*20)+(Foot_force*4))*Foot:mass()) Foot_yaw=Foot:angles():yaw()-Foot_final_rot if (Foot_yaw>180) {Foot_yaw-=360} if (Foot_yaw<-180) {Foot_yaw+=360} Foot_rot=Foot:angles():setYaw(Foot_yaw) Foot:applyAngForce(($Foot_rot*10+Foot_rot*2)*Foot:mass()*-1) } elseif (Stage==8) { if (Foot:vel():length()<2.5) { Stage+=1 } else { Foot:applyForce(Foot:vel()/Foot_fall*Foot:mass()*-1) Foot:applyAngForce(Foot:angVel()/2*Foot:mass()*-1) } } elseif (Stage==9) { soundStop(2) soundPlay(3,0,"vehicles/tank_turret_stop1.wav") soundVolume(3,0.375) soundPlay(4,0,"npc/dog/dog_footstep"+toString(floor(random(1,5)))+".wav") Offset=0-Offset if (Foot==Left) { Foot=Right } else { Foot=Left } Stage+=1 } elseif (Stage<10+Delay & Stage!=0) { Stage+=1 } elseif (Stage==10+Delay) { Stage=0 } interval(10) } [/code] Normal Code [code] @name Walking Chip MkIV @inputs Left:entity Right:entity W A S D R Space Active @outputs Jump Effect Hide @persist Foot_pos_array:array Heading Stage Offset Speed Foot:entity Sensativity Host:entity @persist Angle:angle Foot_dest_rot Foot_final_rot Foot_rot:angle Speed_rot On Stride Foot_lift Foot_fall Delay @persist Dest:vector Foot_final_pos:vector Foot_dest_pos:vector Foot_force:vector Offset_static @persist Left_rot:angle Right_rot:angle Dest_l:vector Dest_r:vector Jet Jump_jet Ride_height if (duped()) {reset()} if (first()) { #insert *On before the final brackets on lines 124 and 126 to make the robot collapse when not in use On=0 Hide=1 Host=entity():isConstrainedTo() Heading=Host:angles():yaw() Foot_pos_array=array() Foot=R
Not really new thread material is it?
[QUOTE=Hunta;18467030]Not really new thread material is it?[/QUOTE] I agree with Hunta, you should have just edited your previous post. Don't you know where the edit button is?
will this make the pelvis stay higher up than the legs?
Sorry, you need to Log In to post a reply to this thread.