angular movement

You must understand the Game Editor concepts, before post here.

angular movement

Postby 157pl » Wed Oct 20, 2010 12:16 am

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?
User avatar
157pl
 
Posts: 109
Joined: Thu May 13, 2010 10:49 pm
Location: AZ
Score: 3 Give a positive score

Re: angular movement

Postby jimmynewguy » Wed Oct 20, 2010 12:34 am

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.
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: angular movement

Postby 157pl » Wed Oct 20, 2010 3:04 am

thx i didn't know that those existed. :D
User avatar
157pl
 
Posts: 109
Joined: Thu May 13, 2010 10:49 pm
Location: AZ
Score: 3 Give a positive score

Re: angular movement

Postby lcl » Thu Oct 21, 2010 11:45 am

Jimmy, for some reason angle and directional_velocity aren't working in global code... :o It's frustrating.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: angular movement

Postby jimmynewguy » Thu Oct 21, 2010 8:22 pm

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..
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: angular movement

Postby lcl » Fri Oct 22, 2010 3:34 pm

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
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: angular movement

Postby jimmynewguy » Fri Oct 22, 2010 6:54 pm

odd. this .ged seems to work but others don't. :|

EDIT: Doesn't work anymore...?
Attachments
Angular_Movement.ged
(967 Bytes) Downloaded 108 times
Working on a probably too ambitious project! Wild-west-adventure-RPG-shooter-thing.
User avatar
jimmynewguy
 
Posts: 1137
Joined: Sat Mar 31, 2007 6:27 pm
Score: 89 Give a positive score

Re: angular movement

Postby lcl » Fri Oct 22, 2010 8:46 pm

Nope, doesn't work. :o
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: angular movement

Postby tintran » Fri Dec 24, 2010 3:36 am

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.
Attachments
angular_movement.ged
(1.63 KiB) Downloaded 106 times
User avatar
tintran
 
Posts: 157
Joined: Fri Dec 24, 2010 1:34 am
Score: 30 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest