# Need some help on some code

**URL:** <https://forum.kirupa.com/t/need-some-help-on-some-code/302842>\
**Category:** flash\
**Created:** [January 8, 2010, 1:08pm UTC](https://forum.kirupa.com/t/need-some-help-on-some-code/302842 "2010-01-08T13:08:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuTi](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@JuTi](https://forum.kirupa.com/u/JuTi)\
**Post date:** [January 8, 2010, 1:08pm UTC](https://forum.kirupa.com/t/need-some-help-on-some-code/302842/1 "2010-01-08T13:08:13Z")

</div>

Alright, we have a symbol, called ‘auto’  
here’s his code:

```auto
onClipEvent (load) {
    xto = _x+1;
    yto = _y+1;
    dir = 1;
    dirto = 0;
    rotspeed = 30;
    speed = 20;
    //dis = Math.sqrt(((xto-_x)*(xto-_x))+((yto-_y)*(yto-_y)));
    dirdif = 0;
}
onClipEvent (mouseDown) {
    xto = _root._xmouse;
    yto = _root._ymouse;
}
onClipEvent (enterFrame) {
    dis = Math.sqrt(((xto-_x)*(xto-_x))+((yto-_y)*(yto-_y)));
    if (dis>10) {
        dirto = Math.atan2(yto-_y, xto-_x)/(Math.PI/180);
        dirdif = dirto-dir;
        dirdif = dirdif-360*Math.round(dirdif/360);
        dir += Math.max(-1*rotspeed,Math.min(rotspeed,dirdif));
        _rotation = dir;
        _x += Math.cos(dir*Math.PI/180)*speed;
        _y += Math.sin(dir*Math.PI/180)*speed;
    }
}

```

well, this is working all fine.  
The object turns and goes to where we click.

What we want now is that, when object ‘rots’ is in his way he will choose the shortest way around it.

Can anyone help me on this?

thanks in advance
