See attachment above. I’m trying to make the object/model face the player at the beginning of the placement time. Notice how it always faces a single direction no matter where and what I place.
I’ve tried using lookAt, however it doesn’t work. This is the script I’m using to get the active live rendering before placing the object down.
RunService.RenderStepped:Connect(function()
if PlacingObject == true and PrimaryPart then
Mouse.TargetFilter = PreviewObject
local Hit = Mouse.Hit
if PrimaryPart then
local ObjectCFrame = CFrame.new(Hit.Position.X, Hit.Position.Y +
PreviewObject.PrimaryPart.Size.Y/2 + Offset, Hit.Position.Z)
local Diff = ObjectCFrame.Y - Character.HumanoidRootPart.Position.Y
local ObjectAngles = CFrame.Angles(0,math.rad(RotationAmount),math.rad(-90))
PreviewObject:SetPrimaryPartCFrame(ObjectCFrame * ObjectAngles)
The rest of the code is cut off because it is irrelevant to this issue. Are there any ideas to get it to face the player when it starts the placement preview? Perhaps by using the calculation to store into RotationAmount. I think calculating the CFrame.Angles at the beginning would help, but I don’t know how to get the Y of the CFrame.Angles() to face the player at all.
Thank you in advance and I’ll try my best to elaborate more in comments if necessary.
I don’t understand why lookAt wouldn’t work. You need to elaborate on that. To extract the RotationAmount from that, you can do something like
local _, RotationAmount = CFrame.lookAt(sign.Position, player.HumanoidRootPart.Position):ToOrientation()
--Because RotationAmount is already in radians, we don't need to use math.rad anymore
--also math.rad(-90) is just math.pi*-.5, use that instead of redundantly calling the function
--inside RenderStepped
local ObjectAngles = CFrame.Angles(0, rotationAmount, math.pi*-.5)
Alpha is the angle between the 2 points denoted as (X1, Y1) and (X2, Y2).
It is in 2D, the implementation of 3D is simple because we only have to look at 2 axes (like in the 2D case), the Z and X axis. So the Y axis would just become the Z axis. In code:
local p0 = ...; -->> Whatever Vector3 position
local p1 = ...; -->> Whatever Vector3 position
local YAngle = math.atan2((p1 - p0).Z, (p1 - p0).X) -->> In radians.