gun swirl

Game Editor comments and discussion.

gun swirl

Postby frodo » Wed May 24, 2006 12:48 am

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
User avatar
frodo
 
Posts: 127
Joined: Tue Mar 21, 2006 6:53 pm
Location: universe
Score: 2 Give a positive score

Postby Fuzzy » Wed May 24, 2006 1:07 am

You mean there is a bias in the direction that the actor wants to turn?
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby makslane » Wed May 24, 2006 1:52 am

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;
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby frodo » Wed May 24, 2006 2:25 am

Makslane, that dosn't work
User avatar
frodo
 
Posts: 127
Joined: Tue Mar 21, 2006 6:53 pm
Location: universe
Score: 2 Give a positive score

Postby makslane » Wed May 24, 2006 2:48 am

What's the problem?
makslane
Site Admin
 
Posts: 3947
Joined: Sat Apr 05, 2003 6:47 pm
Score: 182 Give a positive score

Postby DilloDude » Wed May 24, 2006 5:02 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby frodo » Wed May 24, 2006 2:20 pm

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
User avatar
frodo
 
Posts: 127
Joined: Tue Mar 21, 2006 6:53 pm
Location: universe
Score: 2 Give a positive score

Postby DilloDude » Thu May 25, 2006 12:55 am

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.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby frodo » Thu May 25, 2006 2:18 pm

in draw actor, it dosn't reconize "todir", "faceangle", and "n"
User avatar
frodo
 
Posts: 127
Joined: Tue Mar 21, 2006 6:53 pm
Location: universe
Score: 2 Give a positive score

Postby Joshua Worth » Thu May 25, 2006 10:24 pm

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
Stay sweet
User avatar
Joshua Worth
 
Posts: 515
Joined: Tue Jul 19, 2005 12:00 am
Location: Stralia
Score: 5 Give a positive score

Postby frodo » Fri May 26, 2006 12:04 am

It's just the same as before...
User avatar
frodo
 
Posts: 127
Joined: Tue Mar 21, 2006 6:53 pm
Location: universe
Score: 2 Give a positive score

Postby frodo » Fri May 26, 2006 12:23 am

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?
User avatar
frodo
 
Posts: 127
Joined: Tue Mar 21, 2006 6:53 pm
Location: universe
Score: 2 Give a positive score

Postby frodo » Fri May 26, 2006 12:28 am

doesn't "=!" mean does not equal?
That's why I did:

Code: Select all
if(gunangle =! angle)ChangeAnimationDirection("Event Actor", FORWARD);
User avatar
frodo
 
Posts: 127
Joined: Tue Mar 21, 2006 6:53 pm
Location: universe
Score: 2 Give a positive score

Postby Fuzzy » Fri May 26, 2006 4:47 am

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 <>.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Postby frodo » Fri May 26, 2006 6:37 pm

my idea still doesn't work.
User avatar
frodo
 
Posts: 127
Joined: Tue Mar 21, 2006 6:53 pm
Location: universe
Score: 2 Give a positive score

Next

Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest