# how do I rotate float3?

Discussion in 'Physics for ECS' started by Conspiracy, Jan 18, 2020.

1. ### Conspiracy

Joined:
Oct 22, 2016
Posts:
40
I want to rotate a float3 -90 degrees. i.e from (0,1,0) to (1,0,0). I tried to multiply the float3 with quaternion.AngleAxis but that doens't work. If anyone knows how to do this without manually calculating the matrices pls help..

2. ### Antypodish

Joined:
Apr 29, 2014
Posts:
10,775
New rotation = current rotation * rotation offset
New vector = new rotation * vector

3. ### Conspiracy

Joined:
Oct 22, 2016
Posts:
40
how would I do it in code tho? like I said multiplying quaternion with float 3 doesnt work so....?
Thanks

DragonCoder likes this.
4. ### Antypodish

Joined:
Apr 29, 2014
Posts:
10,775
I suggest look into topics covering adding and subtracting rotations, using quaternions.

In Dots you of course need use math.mul, instead *
Order of multiplication is extremely important, when comes to deal with rotations.

erenaydin, Chmyke and Conspiracy like this.
5. ### Conspiracy

Joined:
Oct 22, 2016
Posts:
40
Nvm, I just use matrix calculation.
For anyone wondering if you wanna rotate float3 to the z-axis just use this formula/code :

float3 vector
float3 rotatedVector = new float(vector.y, -vector.x, vector.z)

basically you just switch the y and x and multiply x with -1

Last edited: Jan 18, 2020
6. ### Riderrr

Joined:
Mar 6, 2015
Posts:
1
You can multiply it by cos/sin of target angle. For example:

Code (CSharp):
1.
2. float angle = -90;
3.
4. float x = 1;
5. float y = 0;
6. float z = 0;
7.
8. float3 newVector = new float3(
9.  x * math.sin(math.radians(angle)),
10.  y * math.cos(math.radians(angle)),
11.  z
12. );