Hello, thanks for visiting GameML, if you are a Game Maker user, this is the site for you, please sign up, or login if you are already a member, or just browse the site! Welcome to GameML!

ATTENTION MEMBERS!!! USERS CAN NOW SIGN UP AGAIN!
Log in

I forgot my password

Search
 
 

Display results as :
 


Rechercher Advanced Search

Site Hits
Free hit counter
These stats started at 0 on July 7th 2009
GameML File Sharing
USERNAME: gamemladmin@gmail.com PASSWORD: gamemlsite Upload Here: http://gameml.iowoi.org/GameML-File-Sharing-h3.htmPlease add only games.
Create A GAMEML BLOG!
Make a Blog on GameML:http://gamemlblogs.wetpaint.com
Keywords


why use vectors?

View previous topic View next topic Go down

why use vectors?

Post by slayer 64 on Sun Jul 05, 2009 9:09 am

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...
Code:
direction=point_direction(x,y,other.x,other.y);
this is how you do it using vectors.
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;
Second, you need to get the magnitude. you can use point distance but that won't work when you get into 3d. so i will use sqr() and sqrt(), which is square and square root.
Code:
var m;
hspeed=x-other.x;
vspeed=y-other.y;
m=sqrt(sqr(hspeed)+sqr(vspeed));
Next, you need to normalize the components. normalizing scales the vector to a length of 1.
Code:
var m;
hspeed=x-other.x;
vspeed=y-other.y;
m=sqrt(sqr(hspeed)+sqr(vspeed));
hspeed/=m;
vspeed/=m;
so now, the object will move towards the other object at a speed of 1. i can set the speed by changing the magnitude before i normalize.
Code:
var m;
hspeed=x-other.x;
vspeed=y-other.y;
m=sqrt(sqr(hspeed)+sqr(vspeed))/8;
hspeed/=m;
vspeed/=m;
the object will move at a speed of 8 now.
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;
i will go back and improve this if anyone is confused.
avatar
slayer 64
GameML Noob
GameML Noob

Posts : 20
Points : 30315
GameML Reputation : 8
Join date : 2009-07-05
Age : 27

View user profile

Back to top Go down

Re: why use vectors?

Post by -js1210- on Sun Jul 05, 2009 11:17 am

What are the advantages of using vectors in 2D games? Why is it any better?
avatar
-js1210-
Super 500 GML
Super 500 GML

Posts : 1298
Points : 32702
GameML Reputation : 27
Join date : 2009-06-02
Age : 22
Location : United States

View user profile http://www.yoyogames.com/members/js1210

Back to top Go down

Re: why use vectors?

Post by slayer 64 on Sun Jul 05, 2009 12:11 pm

-js1210- wrote:What are the advantages of using vectors in 2D games? Why is it any better?
not much advantage in 2d games, unless your making lots of complicated code. like for bouncing a ball of a line.
avatar
slayer 64
GameML Noob
GameML Noob

Posts : 20
Points : 30315
GameML Reputation : 8
Join date : 2009-07-05
Age : 27

View user profile

Back to top Go down

Re: why use vectors?

Post by 3d on Sun Jul 05, 2009 1:48 pm

i didnt read that fully, are there vectors in 3d games (to clear up for others, to lazy to explain anything)

_________________
Creator of GameML, Thanks for Visiting!
avatar
3d
Admin
Admin

Posts : 1227
Points : 42336
GameML Reputation : 66
Join date : 2009-05-31
Age : 35
Location : U.S.A

View user profile http://gameml.iowoi.org

Back to top Go down

Re: why use vectors?

Post by Vivi_IX on Wed Jul 22, 2009 9:40 am

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.
avatar
Vivi_IX
Tres GameML Ninja
Tres GameML Ninja

Posts : 164
Points : 30448
GameML Reputation : 14
Join date : 2009-07-09
Age : 27
Location : USA: Painesville, Ohio

View user profile http://www.yoyogames.com/members/Vivi_IX

Back to top Go down

Re: why use vectors?

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum