Friday, 18.08.2017, 10:37
Welcome, Гость | RSS
Site menu
Login form
Login:
Password:
Spotlight (en-ru)
Search
Main » 2010 » April » 5 » GML tutorial - math
22:01
GML tutorial - math
'Popular' math function descriptions for GameMaker
Code
//Tutorial by YellowAfterlife
//Math functions in Game Maker
random(r) /*returns a number between 0 and r. r will never be returned (so, result is within [0..r) range */
random_set_seed(n) /*sets a seed value for random(). may not work properly in some cases. */
randomize() /* set the seed of random() to another random().
it's to make sure that your random is going to be random,
and is a good thing to do after you set seed using random_set_seed() */
floor(x) /* rounds down the value. this way:
floor(2.5) = 2
floor(4.9) = 4
floor(1.2) = 1 */
ceil(y) /* rounds up the value. this way:
ceil(2.5) = 3
ceil(4.9) = 5
ceil(1.2) = 2 */
round(z) /* rounds the value 'in a common way'.
round(2.5) = 3
round(4.9) = 5
round(1.2) = 1
Basically the same can be achieved, using floor(value + 0.5) */
min(x,y) /* returns the less of specified arguments. You can stack up to 16 arguments.*/
max(x,y) /* returns the bigger of specified arguments */
median(x,y,z) /* returns a middle of specified values.
This is actually a very usefull function. To limit position of player object, you need:
player.x = median(player.x,0,room_width) */
lengthdir_x(len,dir) /* does a cos() function, multiplied by len, and converted to degrees.
*/
lengthdir_y(len,dir) /* same, but sin() function */
point_distance(x1,y1,x2,y2) /* returns distance between two specified points */
/* to calculate distance in 3d, you need to do:
point_distance(0,z1,point_distance(x1,y1,x2,y2),z2)
this will work properly */
point_direction(x1,y1,x2,y2) /* shows direction from (x1,y1) to (x2,y2)
if you want to calculate Z-dir, do  
point_direction(0,z1,point_distance(x1,y1,x2,y2),z2) */
abs(value) /* returns the absolute value
abs(-1) = 1
abs(1) = 1
abs(-4343) = 4343 */
sign(value) /* returns the sign of value
sign(4) = 1
sign(-45) = -1
sign(0) = 0 */
frac(value) /* returns a fractional value of number.
basically = value - floor(value) */
//That's all for now.
Views: 1107 | Added by: Root | Rating: 5.0/1
Total comments: 0
Only registered users can add comments.
[ Registration | Login ]
Calendar
«  April 2010  »
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
252627282930
Tag Board
200
Stats

Total online: 1
Guests: 1
Users: 0