3
\$\begingroup\$

I am revamping an engine I have been working on and off on for the last few weeks to use a directional vector to dictate direction; this way I can dictate the displacement based on a direction. However, the issue I am trying to overcome is the following problem; the speed towards X and speed towards Y are unrelated to one another. If gravity pulls the object down by an increasing velocity my velocity towards the X should not change. This is very easy to implement if my speed is broken into a Vector datatype, Vector.X dictates one direction Vector.Y dictates the other (assuming we are not concerned about the Z axis). However, this defeats the purpose of the directional vector because:

  SpeedX = 10
  SpeedY = 15

  [1, 1] normalized = ~[0.7, 0.7]

  [0.7, 0.7] * [10, 15] = [7, 10.5]

As you can see my direction is now "scaled" to my speed which is no longer the direction that I want to be moving in.

I am very new to vector math and this is a learning project for me. I looked around a little bit on the internet but I still want to figure out things on my own (not just look at an example and copy off it). Is there way around this? Using a directional vector is extremely useful but I am a little bit stumped at this problem. I am sorry if my mathematical understanding maybe completely wrong.

\$\endgroup\$
2
  • \$\begingroup\$ If you are moving at X=10, Y=15 then you are moving in the direction [10,15] = [2,3], not [1,1]. I'm not sure what you mean by this not being the direction you want to move in. \$\endgroup\$
    – Donnie
    Dec 9, 2012 at 8:52
  • \$\begingroup\$ A direction vector tells the object which way its moving (and commonly which way its facing). Say for instance [0.7, 0.7] * MySpeed will yield a displacement vector so I can say MyPosition + MyDisplacementVector. \$\endgroup\$ Dec 9, 2012 at 8:58

1 Answer 1

6
\$\begingroup\$

[Obligatory link to They Might Be Giants' "Speed and Velocity", which covers the basic concepts of this issue. And is probably a catchier tune than it has any right to be.]

The gist:

  • Speed is a scalar value stating how fast something is moving.
  • Velocity is a vector value stating how fast something is moving and in what direction.

Velocity can be expressed as a normalised (ie: unit length) vector and a scalar 'speed', but for games it's normally much easier to just store the two multiplied together into a single velocity vector.

Once you're storing your velocity as a scaled vector, you can adjust the vertical component separately from the horizontal component. For example, to apply gravity, you will normally just add gravity * time (or -gravity, depending on which direction your y axis goes and whether you express gravity as a positive or negative number).

If you are using velocity in this way, then you do not normally store speed at all. If you need to do a calculation involving speed, you instead calculate it from the velocity by finding the velocity vector's length.

\$\endgroup\$
1
  • \$\begingroup\$ I just drew it all out on paper and came to the same conclusion; implementing it seems to underline what you are talking about. Thank you very much for clarifying it! \$\endgroup\$ Dec 9, 2012 at 9:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .