vRay = vRay + 2*dot(vNormal,-vRay)*vNormal
action bouncer() // moving object that bounces off all obstacles { var vSpeed[3]; while(1) { vec_set(vSpeed,vector(5*time_step,0,0)); vec_rotate(vSpeed,my.pan); c_move(me,nullvector,vSpeed,0); // move ahead.. if (trace_hit) { // if an obstacle was hit.. vec_bounce(vSpeed,hit.nx); vec_to_angle(my.pan,vSpeed); // set the new direction } wait(1); } }
See also:
Vectors, vec_add, vec_set, vec_inverse, vec_diff, vec_fill ...