Archived

This topic is now archived and is closed to further replies.

GalaxyQuest

Should i use vectors and stuff in rpg?

Recommended Posts

My little rpg demo im making has a view similar to Ultima Online. The game is DirectDraw(2d), no D3D. I hope to implement something cool like arrows flying to target. I also want my engine to have as little difficulty moving from 2d to 3d if I choose to in the future. Currently my movement is pretty cheesy. 8 directional movement on a 2d map. Position is recorded using just an x and y. Same goes for velocity...velocityX, veloctiyY. I am at a point where i can make changes without in the design, so nows a good time to make sure i decide what to do and stick with it. So, i really have 2 questions. A) First, would you recommend using a point structure instead of just x value and y value. - For example: struct Point3D { int x,int y,int z } ...instead of my int x, int y which are seperated by them selves in my classes, etc?? B) (the biggy)Should i consider using vectors for movement/velocity instead of my int x, int y, int velX, int velY? - I "think" it may be better in the long run, but I really havnt seen much discussion in this forum on it. Do you guys/gals use vectors in you iso games and how do you use them??? please help me... Visit my planet: Planet John Capt. James Tiberious Kirk -- hmm, didnt know ole Capn was a tiberia fan.

Share this post


Link to post
Share on other sites
Don't make your engine too complicated from the start ... maybe you don't finish it because of its planed complexity. My opinion is that its really important to estamate the time u put in and what u get for it. Better finish an simple game than to drop an complex game at 10% finished.

Moving your project from 2D to 3D ...
... i don't think that thats that easy.

For your structs:
You can use the D3DXVECTOR3 from directx the are well overloaded ... and not forget that point coordinates are vectors too.


Edited by - Jonus on March 19, 2001 11:57:46 AM

Share this post


Link to post
Share on other sites
Depends on how familiar you already are with linear algebra (''vectors''). If you know your maths I''d definately advise you to use 3D vector calculations to do your movements etc. It will lead to a much cleaner interface and programming with such a system is actually *easier* not harder as I''ve seen suggested here several times. That''s mostly because of consistency but also because of the many existing resources on the subject.
I use vectors in my engine to good effect. One of the most frequently asked questions in this forum (how to know what tile the mouse is over) was easy to solve once you analyzed it from a LA point of view. Also, you can easily get rid off all those nasty tilex,tiley + offsetx,offsety variables which make smooth movement next to impossible or at least unnecessarily difficult.

So yes, learn the maths and use vectors in your engine, especially if you consider switching to 3D lateron (my game entities already act as in a true 3D enviroment - only when displaying one dimension is lost).

An early demo of my game is at:
home.t-online.de/home/BuschnicK
(note that I''m in the process of replacing the currently very basic vector class with a much more sophisticated and general matrix template)

BuschnicK


Life would be much easier if I had the source code.
http://home.t-online.de/home/BuschnicK/

Share this post


Link to post
Share on other sites
Boy has this forum gettin slow...except for the new posts on map files every day.

Anyways, I was wondering, like i said earlier, I am using right now 8 direction movement. If i were to use vectors, how should i allow for the same 8 directions if i want to?

Do i pre-compute angles for the 8 vectors to determine the 8 n,ne,e,... directions?

Visit my planet: Planet John
Capt. James Tiberious Kirk -- hmm, didnt know ole Capn was a tiberia fan.

Share this post


Link to post
Share on other sites
The big question is are you treating the world as having x,y,z currently?

I remember writing my first game which was pseudo 3D. 2.5 3D
to be precise

I got into trouble when the player had to jump over an obstacle. I did not
have the third dimension. Just because my playing field looked 3D and scanned
a ray against a flat plane in 2D height was not important , only X and Z was
important to me. Alas the missing Y dimension was.

Whilst I tend to agree with an earlier post about not complicating the engine I
wish somebody had told me what I am telling you now back then!!!! The only reason
I am saying this is because you express a desire that moving to full 3D will
not cause you problems at a later date.

Think of your presentation layer as just that. Whether you push polygons or tiles
makes no difference. Your presentation layer should not encumber your design.

Ok sorry for all this but as far as I am concerned Isometric is 3D. The projection
method just so happens to have dropped the perspective transform.

Now after all that I do think you should create 3D vectors. You already have hinted
at the answer by storing the eight directions as angles.

Let''s do this in 2D but taking into consideration that Z is the depth not the height.
I want an object to travel 20 units at a 45 degree angle and at a velocity of 4 units.
I prefer to work in radians when working with COS/SIN but it is up to you. Make a look
up table for the tables.

// note this is a one off the rest is just incremental

vel_dist=4;
angle=45;
tot_iter=20;

velx=cos_table[angle]*vel_dist;
velz=sin_table[angle]*vel_dist;

for each iteration of movement

object_world_x+=velx;
object_world_z+=velz;
tot_iter--;

Now your object can move through 360 degrees in the X,Z plane using only incremental
calculations and a one off setup.

A vector has direction and a magnitude. The angles represent the direction and the
magnitude is vel_dist. This is not the only way to do this but it works.

Share this post


Link to post
Share on other sites
I am still designing the objects for my map. In fact, that is why i posted the question about using a struct Point3D for position, so that i can use 2D or 3D (or 2.5D ).

Question:
If in a 2d world, i have x,y...x is the east/west of map and y is the north/south of map.
But if i move my 2d map into 3d, the axis'' change?!? So, my X is still east/west, but now Z is north/south AND Y IS NOW the height of the tile. If we are in isometric, i guess this would be like a tile either being closer to the screeen(mountain) or further down in the screen(valley)

Is this the correct use of the axis in 3d/isometric ?

Question:
quote:

Now your object can move through 360 degrees in the X,Z plane using only incremental calculations and a one off setup.


Can you explain what you mean by "one off setup" I''ve never heard that terminology before?

Also, would you recommend using floats for your movement?
thanks.

Visit my planet: Planet John
Capt. James Tiberious Kirk -- hmm, didnt know ole Capn was a tiberia fan.

Share this post


Link to post
Share on other sites
>>If in a 2d world, i have x,y...x is the east/west of map and y is the north/south of map.
But if i move my 2d map into 3d, the axis' change?!? So, my X is still east/west, but now
Z is north/south AND Y IS NOW the height of the tile. If we are in isometric,
i guess this would be like a tile either being closer to the screeen(mountain) or
further down in the screen(valley)
Is this the correct use of the axis in 3d/isometric ? <<

Correct

Try to imagine your world coordinates as being x,y,z as you pointed out.

Your screen has only two dimensions. It just so happens that Y ends up confusing
issues. But you have transformed into view space and dropped the third coordinate.

I am going to keep this to a bare minimum. No optimisation but only to try and
describe what you may need to grasp.

For simplicity sake let's say your engine consists of a ground tile and it lives in
a possible 64x64x64 cube.

I want this tiles height to be smack bang in the middle of the cube.

So it's local coordinates (Cartesian) are..

top left x1=-32, y1=0, z1=-32
top right x2=32, y2=0, z2=-32
bottom left x3=-32, y3=0, z3=32
bottom right x4=32, y4=0, z4=32

You have described your tile has a polygon. If your tile is masked then simply describe
the bounding area it makes no difference.

When you create a tile you have manually transformed it. If I took the following coordinates
and passed them through a 3D tranformation matrix with the appropriate camera I would
get your tile. So try to imagine that you are actually plotting pre transformed polygons.

But you now want to position it into the world. Because you are not rotating
(Because you have manually rotated the tile) then you simply translate this to the
world coordinates.

tile_world_x=64;
tile_world_y=0;
tile_world_z=64;

for all of your tile vertices simply add the world coordinate. So x1+=tile_world_x ,
y1+=tile_world_y,z1+=tile_world_z and so on.

Later on you can get into zooming and stuff but the most important aspect is that you
have described the geometry of your objects.

Guess what you have done you have supplied 3D info to a 2D object. In a traditional
3D engine you do it the other way round but you have cut out the screen transformation
because you have done it by hand. You have cached the result

So carry on with your drawing method but store full X,Y,Z against the objects.


>>Can you explain what you mean by "one off setup" I've never heard that terminology <<

Sorry what I meant was when you want an object to move you only have to calculate the
potentially expensive operation of the multiply once.

So..

Player decided to fire an arrow
figure out direction and velocity
block player from firing another arrow or use a timer to decide when
they can do that again.

on each frame until hit something or arrow fell out of range
move arrow

>>Also, would you recommend using floats for your movement?
thanks. <<

Difficult question It all depends on what you want to achieve. I tend
to store everything in integers use floats to calculate movement then convert
back to integers. I suppose one rule could be if most of your calculations
are in integers then demote floating point, otherwise flip the promotion!






Edited by - ancientcoder on March 21, 2001 8:16:39 PM

Share this post


Link to post
Share on other sites
I had asked the question on floats because with my cheesy movement routines, any of the diagonal movements where making movements further then they should. (i popped the question by accident in the graphics forumn.) One suggestion was to use floats and a circle radius to get the currect movement amount and then drop that float x,y position to integer values.

Once that suggestion came up, the whole vector notion in my head started and I wasnt sure what others did about it...and here i am.

BTW ancient, thanks for your previous explainations...

Visit my planet: Planet John
Capt. James Tiberious Kirk -- hmm, didnt know ole Capn was a tiberia fan.

Share this post


Link to post
Share on other sites
Yep you could use a circle. In fact you used that previous
code I showed you with COS and SIN and dist being the radius.

You could have a super arrow weapon which did a full
360 degree attack!!!

Good luck and keep on thinking of the big picture :-)






Share this post


Link to post
Share on other sites
>
Anyways, I was wondering, like i said earlier, I am using right now 8 direction movement. If i were to use vectors, how should i allow for the same 8 directions if i want to?
<

Trivial. Suppose you have your x and y vector components denote the axis you are already using (the 2D map area). z would be hight above the map then.
If you wanted to move in the eight map directions you''d set your speed vectors up like so:
(1,0,0) moves in the positive x direction, one unit at a time.
for diagonal movement you''d get
(1,1,0) though this would lead to faster movement when moving diagonal (the vector is longer), to remedy this you''ll have to normalize the vector (scale to unit length) and then scale it to fit your movement speed. Normalizing a vector means adding the squares of all components and taking the square root of that. That''s the euklidean vector norm (length of the vector) to make the vector unit length you devide each component by the length.

regards,

BuschnicK

Life would be much easier if I had the source code.
http://home.t-online.de/home/BuschnicK/

Share this post


Link to post
Share on other sites