Page 1 of 1

angular movement

PostPosted: Wed Oct 20, 2010 12:16 am
by 157pl
i have been working on wrighting functions using global code so that i can load them into games. this way i can program faster and still edit the code. i am trying to make a code that moves at a speed that you input and at an angle that you input but i cant think of a code that will make it move at the angle at the right speed. can someone help?

Re: angular movement

PostPosted: Wed Oct 20, 2010 12:34 am
by jimmynewguy
Code: Select all
angle = 180; // Put whatever angle in for 180
directional_velocity = 2; // Put whatever speed for 2

or if you really wanted to make your own function in the global code put:
Code: Select all
// Change angular_movement to whatever name and ang and speed to whatever names. Just make sure you // change them accordingly below
void angular_movement(double ang, double speed)
{
angle = ang;
directional_velocity = speed;
}

Then when you want to use it
Code: Select all
angular_movement(180,2);

This would give you the same result as the first code.

Re: angular movement

PostPosted: Wed Oct 20, 2010 3:04 am
by 157pl
thx i didn't know that those existed. :D

Re: angular movement

PostPosted: Thu Oct 21, 2010 11:45 am
by lcl
Jimmy, for some reason angle and directional_velocity aren't working in global code... :o It's frustrating.

Re: angular movement

PostPosted: Thu Oct 21, 2010 8:22 pm
by jimmynewguy
Code: Select all
void angular_movement(int ang, double speed)
{
angle = ang;
directional_velocity = speed;
}

It seems to work if ang is an integer and speed a double..

Re: angular movement

PostPosted: Fri Oct 22, 2010 3:34 pm
by lcl
Doesn't work for me still. :(
Placed your code in global code and wrote to actor's draw actor code:
Code: Select all
angular_movement(5, 5);

But it didn't move. :o

Re: angular movement

PostPosted: Fri Oct 22, 2010 6:54 pm
by jimmynewguy
odd. this .ged seems to work but others don't. :|

EDIT: Doesn't work anymore...?

Re: angular movement

PostPosted: Fri Oct 22, 2010 8:46 pm
by lcl
Nope, doesn't work. :o

Re: angular movement

PostPosted: Fri Dec 24, 2010 3:36 am
by tintran
didn't work for me either.
But after trying a few ways, i found that if you initialize the angle or the directional_velocity variables before calling the function angular_movement defined in global code it works.
by adding
Code: Select all
angle=0;
or
Code: Select all
directional_velocity=0;

before the function call, it will work.

attached is a .ged that shows 3 actors
1 actor initializing the angle before the function call (works).
1 actor initializing the directional_velocity before the function call (works).
1 actor just calling the function without initializing any of the variables first(doesn't work).

By the way, the below .ged has defined double for angle and double for speed, it works, it seems to be an initialization problem or maybe how GE optimizes code maybe? (like checking to see if the variables are initialized at all before it even tries to even animate your player? not sure. but hopefully it'll get rid of some frustrations for beginners like myself.