Author Topic: Vector interpolation question - steering behaviour  (Read 996 times)

Offline FutureCow

  • HelpEditor
  • Prof. Inline
  • ******
  • Posts: 680
    • View Profile
This should be relatively simple but vectors are making my head hurt just now.

I'm looking at implementing steering behaviour (ie. gradually changing a vector to another one). Does anyone have pseudocode or an example they can throw in my direction?

The easiest way to describe it is with a car example :
Lets say I've got a car going North at 10 m/s. I want to change that so that the car is eventually going East at 10 m/s. Every game update the speed will be 10m/s. The player turns a steering wheel a certain amount so that every game update the car is facing a bit more to the east, a bit less to the north, but still doing the same speed.

My code currently has an initial vector and a starting point on a grid. I know when the player hits a particular location I need to start changing the vector so it gradually moves to point at a different location. I'm not sure of the calculation to set the new facing direction as I only know it as an angle from the current facing direction, not as a vector.

Edit - Just found that it looks to be
X=cos(angle) * speed
Y=sin(angle) * speed
« Last Edit: 2012-Jun-19 by FutureCow »