[AS3] Help with some trig and creating a squid. :D

Well… I have come to the end of my current knowledge of how the hell to do the following. Essentially I am attempting to create a simple game that involves a squid which follows the mouse pointer, and some fish and stuff… However, in order to create this game I must first create a working squid. :slight_smile:

Here is what I have so far: http://www.2dsquid.com/alpha

Now, what I have so far is ok. It works… Sort of. But I want to change things and make it more realistic. Some of the things I want to implement are:
[LIST]
[]Vector dynamics. I want the tentacles of the squid to move and “stream” behind the squid… Essentially as the head moves the tentacles follow behind, but if the head turns then the tentacles wont instantly turn. I have no idea how to do this…
[
]Minimum turn radius… I have been trying and trying to do this but whatever I do there is some bug that I can’t figure out how to remove. Below the following source is a method I tried to implement… With failure.
[*]A better swimming effect. I currently have a simple swimming effect, but it really isn’t that great… Check the code below to make recommendations…[/LIST]Those things would be a great start, and if I can see how to do them I can probably figure out everything else I need to do… Anyways on to the code:


    public class Squid extends MovieClip
    {

        var speed:Number;
        var blurSpeed:Number;
        var dx:Number;
        var dy:Number;
        var blur:BlurFilter = new BlurFilter(5, 5, BitmapFilterQuality.LOW)
        var angle:Number=0;
        var radius:Number;
        var fixedRadius:Number;
        var radiusAdjust:Number = 8;
        var testRotation:Boolean = false;
        
        var rotationSpeed:Number;
        
        public function Squid()
        {
            this.stage.addEventListener(MouseEvent.MOUSE_MOVE, radiusChanger);
        }
        
        function init(spd, bspd, radiusMod):void
        {
            speed = spd;
            blurSpeed = bspd;
            fixedRadius = radiusMod;
            radius = fixedRadius;
            rotationSpeed = 100;
            rotation = 0;
            squee2.rotation = 90;
        }
        
        function updatePosition():void {            
            //Set Up
            blurSquid();
            var distance = Math.sqrt(Math.pow(dx, 2)+Math.pow(dy, 2));
            
            //Rotation Handling
            var radians:Number=Math.atan2(dy,dx);            
            var rotateTo:Number = (radians/Math.PI)*180;
            
            rotation = rotateTo;           
            
            //Direction Calc
            var rad = rotation * Math.PI/180;
            var someX = Math.cos(rad)*distance;
            var someY = Math.sin(rad)*distance;
            
            if(distance > 200){
                someX += Math.cos(distance*Math.PI/180) * 80 * distance/700;
                someY += Math.sin(distance*Math.PI/180) * 60 * distance/700;
            }
            
            //Movement
            x += someX/speed;
            y += someY/speed;

            //Bounce Adjusting
            if(radius > 1) radius -= .1;
            if(distance < 30 && radius < fixedRadius) {
                if(radiusAdjust > 1) { radiusAdjust -= 1 }
                radius += radiusAdjust;
            }
            
            x -= Math.cos(-rad) * radius;
            y += Math.sin(-rad) * radius;
        }
        
        function radiusChanger(event:Event):void
        {
            if(radiusAdjust < 8) radiusAdjust += 1;
        }
        
        function blurSquid():void {
            this.filters = [blur]
            blur.blurX = Math.abs((dx)/blurSpeed);
            blur.blurY = Math.abs((dy)/blurSpeed);
        }
        
        function setCoords(varX, varY):void
        {
            dx = varX - x;
            dy = varY - y;
        }
    

    }

I tried to implement rotation radius using the following method, however… It has a bug.


            rotationSpeed = 
            var dr = rotateTo - rotation;

            if(rotation != 90&&!testRotation) { rotation = 90; testRotation = true; }
            else if(rotation != rotateTo) rotation += dr/rotationSpeed;

This method works quite well however I get a weird but where the squid goes insane when the mouse is directly left of the squid. Test it here:
http://www.2dsquid.com/alpha2