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

How would I exclude specific cords with CFrame LookAt Mouse.Hit.p?

Asked by 6 years ago

I'm trying to get this part to look at the mouse position. This is what I have:

local Mouse = game.Players.LocalPlayer:GetMouse()
local Part = workspace.Part
Part.CFrame = CFrame.new(Part.CFrame, Mouse.Hit.p)

(Im using RenderStepped in the actual code, to keep the CFrame updated) This code will get the part to look at my mouse position. But the part is rotating using all of its axis points, how would I get the part to look at my mouse position using only its Y cord?

0
You would just use the y cord from the vector3 User#5423 17 — 6y
0
You're only trying to make the Character's y coordinate be equivalent to the Mouse's Y coordinate? KingLoneCat 2642 — 6y
0
Part.CFrame = CFrame.new(Part.CFrame, Vector3.new(Part.CFrame,Mouse.Hit.p.Y,Part.CFrame) -- I already tried this and it is not working User#2146 0 — 6y
0
Im trying to get the part to look at the mouse position, but LookAt is rotating it using all of its axis points. I need it to only rotate using its Y axis User#2146 0 — 6y
0
Part.CFrame = CFrame.new(Part.Position, Vector3.new(Part.Position.X, Mouse.Hit.p.Y, Part.Position.Z)) -- This should work. KingLoneCat 2642 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Please note that GetMouse().Hit returns a read only CFrame. If you wish the part to become at the position of the mouse;

Part.CFrame =Mouse.Hit

if on the other hand you wish for the part to go halfway;

Part.CFrame = Part.CFrame * Mouse.Hit

if you only wish to use the y co-ordinate, then it would look like this;

Part.CFrame = CFrame.new(Part.CFrame.x,Mouse.Hit.y,Part.CFrame.z) 

I wasn't very sure what you were trying to do, so I just explained how the line would look accordingly. I hope I helped, have a good day!

0
I got it working using the following code: Part.CFrame = Part.CFrame*CFrame.new(Vector3.new(), Part.CFrame:inverse()*Mouse.Hit.p*Vector3.new(1,0,1)) -- But thank you so much for your time! User#2146 0 — 6y
0
That would not work well, but alright, glad you have it working! iamnoamesa 674 — 6y
Ad

Answer this question