Log in
Search
GameML File Sharing
USERNAME: gamemladmin@gmail.com PASSWORD: gamemlsite Upload Here: https://gameml.forumotion.com/GameML-File-Sharing-h3.htmPlease add only games.why use vectors?
4 posters
:: Game Making :: Game Maker Help :: Code Database :: GameMaker Techniques
Page 1 of 1
why use vectors?
vectors are useful for any game. they are really useful in 3d games.
i will show you 2d vectors first.
a vector is a line from 0,0 to any other location. it has vector components, which are the horizontal distance, and vertical distance. it also has a magnitude, which is the length.
you would normally move an object towards another like this...
First, you need to get the components. i will use hspeed and vspeed because it will be more convenient.
you can't use point_direction in 3d, so vectors come in handy.
this is exactly the same process when in 3d, i just make a z and a zspeed variable for the object.
i will show you 2d vectors first.
a vector is a line from 0,0 to any other location. it has vector components, which are the horizontal distance, and vertical distance. it also has a magnitude, which is the length.
you would normally move an object towards another like this...
- Code:
direction=point_direction(x,y,other.x,other.y);
First, you need to get the components. i will use hspeed and vspeed because it will be more convenient.
- Code:
hspeed=x-other.x;
vspeed=y-other.y;
- Code:
var m;
hspeed=x-other.x;
vspeed=y-other.y;
m=sqrt(sqr(hspeed)+sqr(vspeed));
- Code:
var m;
hspeed=x-other.x;
vspeed=y-other.y;
m=sqrt(sqr(hspeed)+sqr(vspeed));
hspeed/=m;
vspeed/=m;
- Code:
var m;
hspeed=x-other.x;
vspeed=y-other.y;
m=sqrt(sqr(hspeed)+sqr(vspeed))/8;
hspeed/=m;
vspeed/=m;
you can't use point_direction in 3d, so vectors come in handy.
this is exactly the same process when in 3d, i just make a z and a zspeed variable for the object.
- Code:
var m;
hspeed=x-other.x;
vspeed=y-other.y;
zspeed=z-other.z;
m=sqrt(sqr(hspeed)+sqr(vspeed)+sqr(zspeed))/8;
hspeed/=m;
vspeed/=m;
zspeed/=m;
slayer 64- GameML Noob
- Posts : 20
Points : 54285
GameML Reputation : 8
Join date : 2009-07-05
Age : 34
Re: why use vectors?
not much advantage in 2d games, unless your making lots of complicated code. like for bouncing a ball of a line.-js1210- wrote:What are the advantages of using vectors in 2D games? Why is it any better?
slayer 64- GameML Noob
- Posts : 20
Points : 54285
GameML Reputation : 8
Join date : 2009-07-05
Age : 34
Re: why use vectors?
i didnt read that fully, are there vectors in 3d games (to clear up for others, to lazy to explain anything)
Re: why use vectors?
Interesting and seemingly complicated, but I think I understand. I'll make sure I look at this again whenever I start my transition into 3D.
:: Game Making :: Game Maker Help :: Code Database :: GameMaker Techniques
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|