# How do I convert speed and heading to a vector?

I'm afraid this might be more rudimentary arithmetic than programming, but vector math has me *really*
confused. Currently I have the following:

```
Vector3 currentPosition;
float currentHeading; //value clamped between 0-360
float currentSpeed; //measured in Unity Units per second
```

Every update, I need to move currentPosition in the direction of currentHeading at a rate of currentSpeed. I know the movement itself can be achieved by converting heading and speed into some vector newPosition, and multiplying (currentPosition*newPosition*Time.deltaTime), but how do I actually convert heading and speed into a single vector?

**Answer** by Downstream
·
Oct 23, 2016 at 12:26 PM

@Sendatsu_Yoshimitsu It's trigonometry. Assuming your heading is from up 0, right 90 degrees. You need the sin and cos functions

x = Mathf.Sin(angle * Mathf.Deg2Rad),

y = Mathf.Cos(angle * Mathf.Deg2Rad),

Vector2 movement = new Vector2(x,y) * speed * Time.deltaTime

**Answer** by Owen-Reynolds
·
Oct 23, 2016 at 04:03 PM

A more Unity-style way is to use the built-ins. The first line takes an arrow pointing north (forward) and spins it around y by your angle (it handles the sin/cos math for you):

```
// length 1 in proper direction:
Vector3 v1 = Quaternion.Euler(0,currentHeading,0)*Vector3.forward;
// correct speed (same as last line in Downstream's example):
v1=v1*currentSpeed;
```

For fun, since you claim to be confused about vector math in general, I put something (almost a book, but small chapters) at taxesforcatses.com/vectorW/TOC.html

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Non physics determinism of floating point math across platforms 1 Answer

how to calculate the angle between two vectors? 6 Answers

GameObject Jittering 0 Answers

Lerp between two direction vector 0 Answers