Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with(oGearBase)
- {
- processed = false
- }
- // 1. compute torque of each "input"
- with(oGearInput)
- {
- torque = (vel_target - vel)/10
- }
- // 2. sum the torques
- //with(oGearInput)
- for(i=0; i<instance_number(oGearInput); i+=1)
- {
- ins = instance_find(oGearInput, i)
- if(!ins.processed) {
- // browse all gears of the current network
- // and compute the torque sum
- torque_sum = 0
- ds_stack_clear(stack)
- ds_list_clear(list)
- ds_stack_push(stack, ins)
- while(!ds_stack_empty(stack)) {
- top = ds_stack_top(stack)
- ds_stack_pop(stack)
- if(!top.processed) {
- ds_list_add(list, top)
- top.processed = true
- torque_sum += top.vel
- if(top.gear_r != noone) { ds_stack_push(stack, top.gear_r) }
- if(top.gear_l != noone) { ds_stack_push(stack, top.gear_l) }
- if(top.gear_u != noone) { ds_stack_push(stack, top.gear_u) }
- if(top.gear_d != noone) { ds_stack_push(stack, top.gear_d) }
- }
- }
- // set the new torque
- roger = min(-1000, max(torque_sum, 1000))
- for(n=0; n<ds_list_size(list); n+=1) {
- ii = ds_list_find_value(list, n)
- ii.torque += roger
- }
- }
- }
- with(oGearBase)
- {
- acc = torque
- }
Advertisement
Add Comment
Please, Sign In to add comment