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!

Join the forum, it's quick and easy

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!
Would you like to react to this message? Create an account in a few clicks or log in to continue.
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: https://gameml.forumotion.com/GameML-File-Sharing-h3.htmPlease add only games.
Create A GAMEML BLOG!
Make a Blog on GameML:http://gamemlblogs.wetpaint.com

why use vectors?

4 posters

Go down

why use vectors? Empty why use vectors?

Post by slayer 64 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.
why use vectors? Aaaaahth
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.
slayer 64
slayer 64
GameML Noob
GameML Noob

Posts : 20
Points : 54285
GameML Reputation : 8
Join date : 2009-07-05
Age : 34

Back to top Go down

why use vectors? Empty Re: why use vectors?

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

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

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

http://www.yoyogames.com/members/js1210

Back to top Go down

why use vectors? Empty Re: why use vectors?

Post by slayer 64 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.
slayer 64
slayer 64
GameML Noob
GameML Noob

Posts : 20
Points : 54285
GameML Reputation : 8
Join date : 2009-07-05
Age : 34

Back to top Go down

why use vectors? Empty Re: why use vectors?

Post by 3d 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)
3d
3d
Admin
Admin

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

https://gameml.forumotion.com

Back to top Go down

why use vectors? Empty Re: why use vectors?

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

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

http://www.yoyogames.com/members/Vivi_IX

Back to top Go down

why use vectors? Empty Re: why use vectors?

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


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