Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to face object towards an object with CFrame?

Asked by
aredanks 117
4 years ago

I want to rotate an object towards something but I have little knowledge on whatever math is required to do it in CFrame. There is a simple way which is however said by the wiki to be deprecated where you use CFrame(object1, object2) but now its recommended to use CFrame.fromMatrix. However, I don't know how to utilize CFrame.fromMatrix correctly.

I presume that LookVector will be used or a unit vector.

--example variables (aka probably use this in ur answer to help me)

local object1 = workspace.Object1
local object2 = workspace.Object2

If you can answer, please explain any math behind it if you can! Should be easy to answer.

0
I actually made a module that contains this function. Check it out here: https://devforum.roblox.com/t/libraries-a-library-extension-module/409035 programmerHere 371 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

The wiki does say that it is deprecated, however you can use something similiar

object1.CFrame =CFrame.new(object1.Position,object2.Position)

to make object1 face towards object2's position.

Ad

Answer this question