# need help calculating x y z velocity from angle

Started by LEN1802 on Tue, 09/01/2020 - 12:53

Topic category: Help with MCreator software

Last seen on 20:29, 31. Mar 2022
Joined Sep 2020
Points:

User statistics:

• Modifications:
• Forum topics:
• Wiki pages:
• Tracker tickets:
• MCreator plugins:
need help calculating x y z velocity from angle
Tue, 09/01/2020 - 13:01 (edited)

Ive been making a projectile that chases after the player,which uses the set movement vector block to move.

i have found a formula to calculate the direction from one 3d point to another, which goes like this:

angle = arccos ( a * b / |a| * |b| );
where:
a * b = ax * bx + ay * by + az * bz
|a| = sqrt( ax * ax + ay * ay + az * az )
|b| = sqrt( bx * bx + by * by + bz * bz )

and ive also found the way to change that angle into a 2d vector for x and y, which is explained in this document:

https://en.wikipedia.org/wiki/Unit_circle

but i dont know the method for turning that 2d formula into a 3d fomula that i can use.

does anyone know how to turn an angle into an X,Y,Z movement vector?

speed should be variable.

Edited by LEN1802 on Tue, 09/01/2020 - 13:01
Last seen on 20:29, 31. Mar 2022
Joined Sep 2020
Points:

User statistics:

• Modifications:
• Forum topics:
• Wiki pages:
• Tracker tickets:
• MCreator plugins:
alright, a friend of mine…
Tue, 09/01/2020 - 19:46

alright, a friend of mine whos good a trig gave me a much easier way to do this than i tried to cook up:

First, find both of the objects 3d positions in space. We'll call these position vectors A and B. Then subtract the vectors, B-A. , you do this by subtracting the individual dimension coordinates, like Bx-Ax, etc. We'll call the resultant vector R, and it is a vector that points directly from point A to point B.

Find the length of vector R. sqrt(Rx^2+Ry^2+Rz^2)

Divide each component of R (minus the ^2) by the total length given by that formula. That gives you a vector that point towards B but is only one unit long. Then multiply that unit vector by whatever your desired velocity is and use that as the velocity for the homing thing.

Last seen on 14:43, 2. Aug 2022
Joined Nov 2018
Points:

User statistics:

• Modifications:
• Forum topics:
• Wiki pages:
• Tracker tickets:
• MCreator plugins: