My 'intelligent' mouse follow - a few questions

In a project for university i am creating a car that follows the mouse. I’m looking at doing a few things (which are completely new) which are different speeds for the surface and collisions. My code below works - but on a very basic level, for instance the hitTest for the surface works, but of course only for a rectangle and not the strange shape of the roads.

The second part (the collision) also works however because it is updating the car position every frame it doesn’t actually move away (45pixels was just a random number to test) and so remains against the tree - convincingly enough to be solid, and you can move away again but i’d prefer more of a bouncing action. perhaps a timer is needed to stop mouse detection for a few moments and allow the car to move away in the opposite direction to which it was travelling?

the last thing i would like to do is put a maximum distance the mouse can be away from the car to avoid confusing the direction and to stop exaggerated speeds (because the car speed is relative to the mouse distance).

my questions are simply on the above three points - all three (hitTest on odd shapes, a timer to stop mouse movement and mouse distance) as i said are something i haven’t touched before so where can i look for simple advice? i’ve downloaded a few FLA’s from kirupa but none are really what i want and i equally am unsure what even to search for. but my main aim with the code is to keepit minimal as can be seen below

anyway, please take a look at my code and have a play if you so so wish :wink: please :stuck_out_tongue:


// follow mouse
onClipEvent (enterFrame) {
    // test surface
    if (_root.Car, hitTest(_root.road)) {
        _root.speed = 15;
    } else {
        _root.speed = 40;
    }
    // collisions
    if (_root.Car, hitTest(_root.tree1)) {
        _root.text = "Collision Detected";
        Car._x = -45;
        Car._y = -45;
    } else {
        _root.text = "No Collision";
        if (_root.text == "No Collision") {
            _x = _x+_xmouse/_root.speed;
            _y = _y+_ymouse/_root.speed;
        }
    }
}


regards, hinch