Advertisement

Jumping entities? why they aren't moving like cars,tanks...

Started by March 28, 2002 05:34 PM
5 comments, last by TrileNOB 22 years, 10 months ago
I have started to make one game. It is a RTS. But now when I select an unit and click to order to move that unit it just ''jumps'' to that location imidiatly! how do I ''slow'' the unit down so i can make ''move efect''? Trile[NOB]
Trile[NOB]
Make a vector from the unit to the destination. that is dest - src

that vector is the number of units to move per frame or second

Then normalize it, so divide the vector by its length. the length is now equal to one

Scale the vector (multiply) by the speed, now every frame it will move gradually!!
Advertisement
To normalize it? To divide it by its lenght?
if the vector is 5 and I divide it with 5 I will get 1!!!
need more info...

Trile[NOB]
Trile[NOB]
quote:
Original post by TrileNOB
if the vector is 5 and I divide it with 5 I will get 1!!!

A vector isn''t (and CAN''T) "be 5". 5 can be the magnitude of the vector, but you''ve ignored its direction in your reasoning.

Say you wished to move from point A(x1, y1) to point B(x2, y2). The vector from A to B, AB = (x2-x1, y2-y1). This is the total distance (in a straight line) and the direction in which to travel. You can then limit the translation by giving your units a speed (a scalar value, such as 2.5). If the magnitude of AB was 30, then moving at a speed of 2.5 it should take 12 time units to arrive at B from A. You therefore divide the distance AB by the speed (2.5) and obtain a vector V ((x2-x2/2.5, (y2-y1)/2.5) which is the unit velocity. Every time slice, you add V to the unit''s current position. Voila! C''est tres facile!

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions ]
Thanks to Kylotan for the idea!
quote:
Original post by TrileNOB
To normalize it? To divide it by its lenght?
if the vector is 5 and I divide it with 5 I will get 1!!!
need more info...

Trile[NOB]


Vectors are 2 or 3 dimensions. Makeing the length equal to one is the whole point, then you can multipy by the speed and get smooth movement
I think I got it.
But, today my friend in school gave me an idea how to make this:
how about using line equation: y-y2=k(x-x2) where k=y2-y1/x2-x1
then I can also determine angle alpha=arctg(k) between that entity and x axis... then when I have X diferance I calculate the speed and then I add it to the X1, with equation I can find Y1 and then I move the entity to that postition...
will this work?



Trile[NOB]
Trile[NOB]
Advertisement
quote:
Original post by TrileNOB
I think I got it.
But, today my friend in school gave me an idea how to make this:
how about using line equation: y-y2=k(x-x2) where k=y2-y1/x2-x1
then I can also determine angle alpha=arctg(k) between that entity and x axis... then when I have X diferance I calculate the speed and then I add it to the X1, with equation I can find Y1 and then I move the entity to that postition...
will this work?



It will do what you want, but ultimately it''ll be more difficult and cause more problems than if you had gone with vectors in the first place.

This topic is closed to new replies.

Advertisement