Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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?

5 comments

0

You would just use the y cord from the vector3

0

You're only trying to make the Character's y coordinate be equivalent to the Mouse's Y coordinate?

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

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

0

Part.CFrame = CFrame.new(Part.Position, Vector3.new(Part.Position.X, Mouse.Hit.p.Y, Part.Position.Z)) -- This should work.

1 answer

✓ Accepted answer

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!

2 comments

0

I got it working using the following code: Part.CFrame = Part.CFrame*CFrame.new(Vector3.new(), Part.CFrame:inverse()Mouse.Hit.pVector3.new(1,0,1)) -- But thank you so much for your time!

0

That would not work well, but alright, glad you have it working!

This discussion is preserved as it was. New answers, comments, and votes are closed.