- Home /

# Add or substract two quaternions/rotations

Hi,

I'm trying to instantiate a shot in front of my ship, but with a custom rotation relative to my ship's local coordinates.

So I tried this:

`Instantiate(shotPrefab, transform.TransformPoint(Vector3(x,y,z)), transform.rotation + Quaternion.Euler(x,y,z));`

But I get this error:

BCE0051: Operator '+' cannot be used with a left hand side of type 'UnityEngine.Quaternion' and a right hand side of type 'UnityEngine.Quaternion'.

So it says I can't add two quaternions.

What's the best way to solve this problem?

**Answer** by Peter G
·
Jun 15, 2011 at 05:34 PM

Multiplying should give you the result you want.

```
transform.rotation * Quaternion.Euler();
```

**Answer** by Cameron_SM
·
Mar 09, 2014 at 07:20 AM

I'm not sure why Peter G's response was voted as correct or voted up, it's simply wrong.

Multiplying a Quaternion by a vector returns **another vector**, and the vector you multiply by should be a direction vector (representing a direction from the origin), not a set of floats representing euler angles in degrees. The result of that multiply operation is that direction vector rotated by the Quaternion.

In order to add two quaternion rotations correctly you multiply them:

```
Quaternion newRotation = transform.rotation * otherTransform.rotation
```

To subtract you need to multiply by the inverse:

```
// Rotate back to the starting position
transform.rotation = newRotation * Quaternion.Inverse(otherTransform.rotation)
```

Alternatively, you can use Euler Angles and simply + (Add) or - (Subtract) the values then convert the result to a Quaternion.

### Your answer

### Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

### Follow this Question

### Related Questions

Can I use Quaternions to get from one point to another? 1 Answer

Quaternions rotating left and right, not forward and back 1 Answer

4 rotations WTF 1 Answer

Relative Rotations and Position calculation 2 Answers

My interpretation of Random.rotation and Random.rotationUniform. Right or wrong ? 0 Answers