How do I Calculate Rotation from Position

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Getting Rotation from positions or look vector
  2. What is the issue? Include screenshots / videos if possible!
    I don’t know how to.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Tried to learn myself.

By the way no,I don’t want to use cframe its expensive for what I making right now.

Can you explain how exactly its working?

I literally gave you a tutorial link

I need explanation in lua code.

Can you elaborate in more detail on what you want?

CFrames are incredibly, incredibly fast. If they’re the right tool for the job, use them.

This is dot product:

a · b = |a| × |b| × cos(θ)

Because we are using unit vectors, |a| and |b| are both one. So the equation simplifies to

a · b = cos(θ)

Where a and b are vectors and theta is the angle.


Now in Roblox; suppose you have a vector aligned to the Z-axis

local vectorA = Vector3.zAxis

And you want to measure the angle between it and another vector, that other vector being the LookVector of a part
You would use the dot product to derive that angle between them

local vectorA = Vector3.zAxis
local vectorB = workspace.Part.CFrame.LookVector
local angle = vectorA:Dot(vectorB)

Remember that angle is actually the cosine of the actual angle, so you will have to remove the cosine by using its inverse function:

local angle = math.acos(vectorA:Dot(vectorB))

However, angle is measured in radians. If you want to convert it to degrees, you will need to use math.deg

local angle = math.deg(math.acos(vectorA:Dot(vectorB)))

1 Like

Not what i looking for but whatever.

Sounds like your problem for not elaborating on what you wanted

I want it like
Vector3.new(X,Y,Z)
like cframe:ToOrientation return

Ok and how exactly is using CFrames “too expensive” for what you’re doing? Have you done proper benchmarks comparing things like CFrame.lookAt to alternatives, if you even have them?

I did benchmark
just purely using cframes resulted in %10 activity
while using Unit to get lookvector resulted in %6 activity
because how many times I need to calculate cframes it became too expensive.

You don’t have a method of deriving angles from LookVectors yet (which is why you’re here asking for help) so that benchmark you did is flawed since you don’t even have what you’re trying to test
Just because getting the LookVector of a part is faster than CFrames does not necessarily mean it’s going to be computationally better at calculating angles
Do not draw conclusions from incomplete data :skull:

Can’t you just use Orientation. Like print(workspace.Part.Orientation).

I need to get orientation from 2 position

Orientation comes from CFrames if I’m not mistaken

In addition he can just do workspace.Part.CFrame.Rotation