Alright so! I am trying to make a system so where-ever your mouse is pointing a part as made and points towards that but if I keep my mouse still the parts come towards the camera. I have tried position, cframe, anchoring, un-anchoring and none of them work.
Code:
01 | wait( 2 ) |
02 |
03 | workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable |
04 |
05 | local mouse = game.Players.LocalPlayer:GetMouse() |
06 | local wplr = game.Players.LocalPlayer.Character |
07 |
08 | while game:GetService( "RunService" ).Heartbeat:Wait() do |
09 | wplr = game.Players.LocalPlayer.Character |
10 | mouse.TargetFilter = wplr |
11 | workspace.EndPart.Position = mouse.Hit.p |
12 | local distance = (wplr.RightHand.Position - mouse.Hit.p).magnitude |
13 | workspace.BeamPart.Size = Vector 3. new( 0.3 , 0.3 , distance) |
14 | workspace.BeamPart.CFrame = CFrame.new(wplr.RightHand.CFrame.p, mouse.Hit.p) * CFrame.new( 0 , 0 , -distance / 2 ) |
15 | end |
Thanks for reading have a nice day! c:
The part's size isn't changing, the part is spazzing out and getting closer to the camera because the mouse's target is the part itself.
What you should do is group the two parts (BeamPart and EndPart) together into a group (in my code, called "Parts") and set the TargetFilter to that. It should take higher priority than the character.
01 | wait( 2 ) |
02 |
03 | workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable |
04 |
05 | local mouse = game.Players.LocalPlayer:GetMouse() |
06 |
07 |
08 |
09 | while game:GetService( "RunService" ).Heartbeat:Wait() do |
10 | local wplr = game.Players.LocalPlayer.Character |
11 | mouse.TargetFilter = workspace.Parts |
12 | workspace.Parts.EndPart.Position = mouse.Hit.p |
13 | local distance = (wplr.RightHand.Position - mouse.Hit.p).magnitude |
14 | workspace.Parts.BeamPart.Size = Vector 3. new( 0.3 , 0.3 , distance) |
15 | workspace.Parts.BeamPart.CFrame = CFrame.new(wplr.RightHand.CFrame.p, mouse.Hit.p) * CFrame.new( 0 , 0 , -distance / 2 ) |
16 | end |