Page 1 of 2

gun swirl

PostPosted: Wed May 24, 2006 12:48 am
by frodo
I have a man with a 360 degree gun animation. His gun always points towards the mouse. Right now, if you have the mouse on the right side of the man, and you quickly put the mouse on the left side of him, he just changes degree from 0 to 180. I want him to swirl his gun around in a full loop to the direction of my mouse. would it be something with "vectoradd"?
Thanks

PostPosted: Wed May 24, 2006 1:07 am
by Fuzzy
You mean there is a bias in the direction that the actor wants to turn?

PostPosted: Wed May 24, 2006 1:52 am
by makslane
Try this in the Draw Actor event:

Code: Select all
//Create some vars
double mouseangle, weight;
int newAnimpos;

//Get current angle between mouse and the actor
mouseangle = direction(xscreen, yscreen, xmouse, ymouse);

//Calculate the new frame based on angle
newAnimpos = (mouseangle/360.0)*(nframes-1);

//Set the weight of motion
weight = 20;

//Calculate the lazy frame position
//Create anim as real, actor variable in the variables button
//Need this because animpos is integer and don hold the fractional changes

anim = (newAnimpos + (weight - 1)*anim)/weight;
animpos = anim;

PostPosted: Wed May 24, 2006 2:25 am
by frodo
Makslane, that dosn't work

PostPosted: Wed May 24, 2006 2:48 am
by makslane
What's the problem?

PostPosted: Wed May 24, 2006 5:02 am
by DilloDude
Put this in global code:
Code: Select all
double getangle(double A, double B)
{
    double result;
 
    result = B - A;
    if(result>180)
    {
        result = 360 - result;
        result *= -1;
    }
    else if (result < -180)
    {
        result = 360 + result;
    }
    return result;
}




double ReDir(double A, double B, double mag)
{
   double ang = getangle(A, B);
    if(abs(mag)<=abs(ang))
    {
        if(ang>0)
        {
            return A + mag;
        }
        else if (ang < 0)
        {
            return A - mag;
        }
        else
        {
            return 0;
        }
    }
    else
    {
        return B;
    }
}

Now, in draw actor, instead of saying faceangle = todir (where faceangle is the angle the animpos represents and todir is the direction to the mouse), say
Code: Select all
faceangle = ReDir(faceangle, todir, n);

where n is the number of degrees to move each frame.

PostPosted: Wed May 24, 2006 2:20 pm
by frodo
dillodude, How do you use global code? when I get done puting in my code, what do I do next? If I press close, it asks me if I realy want to close it. Do I have to save it before closing it out? Thanks

PostPosted: Thu May 25, 2006 12:55 am
by DilloDude
There is a bar at the bottom of the window, that says 'name'. put a name int it (like functions) and click 'add'. That way you can store things in separate blocks of code. You might want things like variables, angle functions, other functions etc.

PostPosted: Thu May 25, 2006 2:18 pm
by frodo
in draw actor, it dosn't reconize "todir", "faceangle", and "n"

PostPosted: Thu May 25, 2006 10:24 pm
by Joshua Worth
He forgot to tell you that you need to create some variables. just click the varibles button a the bottom of the script editor. the variables dont have to be exactly what he said, that was just an example

PostPosted: Fri May 26, 2006 12:04 am
by frodo
It's just the same as before...

PostPosted: Fri May 26, 2006 12:23 am
by frodo
I put this in draw actor:

Code: Select all
int gunangle=man.animpos/man.nframes;
angle=direction(xscreen,yscreen,xmouse,ymouse);
if(gunangle != angle)ChangeAnimationDirection("Event Actor", FORWARD);
if(gunangle=angle)ChangeAnimationDirection("Event Actor", STOPPED);



i didn't work. is there reason why this wouldn't work?

PostPosted: Fri May 26, 2006 12:28 am
by frodo
doesn't "=!" mean does not equal?
That's why I did:

Code: Select all
if(gunangle =! angle)ChangeAnimationDirection("Event Actor", FORWARD);

PostPosted: Fri May 26, 2006 4:47 am
by Fuzzy
frodo wrote:doesn't "=!" mean does not equal?
That's why I did:

Code: Select all
if(gunangle =! angle)ChangeAnimationDirection("Event Actor", FORWARD);


Be careful with that. you want to use != rather than =!. I think you can also use <>.

PostPosted: Fri May 26, 2006 6:37 pm
by frodo
my idea still doesn't work.