Page 1 of 1

Object Variable - Angle

PostPosted: Mon Dec 31, 2012 11:07 pm
by bamby1983
The game editor script reference defines the angle variable as follows:

angle: Move the Actor's angle (0 to 360, from the positive x axis, counterclockwise, in degrees).


I cannot seem to find any example code for this and what it does. Is this an object variable on the lines of xscreen and yscreen and can it be used to modify the rotational angle of an animation?

Re: Object Variable - Angle

PostPosted: Tue Jan 01, 2013 1:31 am
by Hblade
An example code:
Using angle with directional_velocity
Code: Select all
angle=direction(x, y, actor.x, actor.y);
directional_velocity=5;


This will move to an actor at a velocity of 5. You can also "ease in/out" to an actor by using directional_velocity=distance(x, y, actor.x, actor.y)/2;.

Re: Object Variable - Angle

PostPosted: Tue Jan 01, 2013 7:28 am
by bamby1983
Hblade wrote:An example code:
Using angle with directional_velocity
Code: Select all
angle=direction(x, y, actor.x, actor.y);
directional_velocity=5;


This will move to an actor at a velocity of 5. You can also "ease in/out" to an actor by using directional_velocity=distance(x, y, actor.x, actor.y)/2;.


Thanks for the explanation. I'm still not sure as to what the "angle" variable does, though, and how it is different from any user defined variable. I mean if this is a standard in-game variable, then what does it affect? Does it rotate an object or just store the value of direction(x, y, actor.x, actor.y) like any user defined variable would do?

Can this angle variable be used specific to a particular actor (eg., MyActor.angle)?

Re: Object Variable - Angle

PostPosted: Tue Jan 01, 2013 7:58 am
by Hblade
bamby1983 wrote:
Hblade wrote:An example code:
Using angle with directional_velocity
Code: Select all
angle=direction(x, y, actor.x, actor.y);
directional_velocity=5;


This will move to an actor at a velocity of 5. You can also "ease in/out" to an actor by using directional_velocity=distance(x, y, actor.x, actor.y)/2;.


Thanks for the explanation. I'm still not sure as to what the "angle" variable does, though, and how it is different from any user defined variable. I mean if this is a standard in-game variable, then what does it affect? Does it rotate an object or just store the value of direction(x, y, actor.x, actor.y) like any user defined variable would do?

Can this angle variable be used specific to a particular actor (eg., MyActor.angle)?


Angle sets the directional_velocity direction. Example if you say angle=45; then directional_velocity=5; the actor will move at a 45 degree angle.

And yes it can I believe, MyActor.angle should work

Using the code I gave you, you can calculate the angle you are from that other actor Example the player is in the center, and you want to calculate the angle between/to/from the player, this code would do that

Re: Object Variable - Angle

PostPosted: Tue Jan 01, 2013 8:11 am
by skydereign
bamby1983 wrote:
Hblade wrote:An example code:
Using angle with directional_velocity
Code: Select all
angle=direction(x, y, actor.x, actor.y);
directional_velocity=5;


This will move to an actor at a velocity of 5. You can also "ease in/out" to an actor by using directional_velocity=distance(x, y, actor.x, actor.y)/2;.


Thanks for the explanation. I'm still not sure as to what the "angle" variable does, though, and how it is different from any user defined variable. I mean if this is a standard in-game variable, then what does it affect? Does it rotate an object or just store the value of direction(x, y, actor.x, actor.y) like any user defined variable would do?

Can this angle variable be used specific to a particular actor (eg., MyActor.angle)?

angle is an actor variable. Any actor variable can be obtained through means like MyActor.var. The script reference has the list of all built into gE (except pathxpos/pathypos). One thing to watch out for, is that the value of angle becomes 0 when the actor stops moving. This is similar to the velocity variables. So, to prevent this, you would either need to create your own angle variable, or have directional_velocity set to non-zero values.