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

mouse Target Position?

Asked by 9 years ago

How would I get mouse.Target position?


mouse.Button1Down:connect(function() pcall(function() print(mouse.Target) print(Target.p) local Lazor = Instance.new("Part",workspace.Base) Lazor.Size = Vector3.new(11,2,mouse.Target.p) -- I need it for this... Lazor.Name = "Lazor" while wait() do Lazor.Position = Character.Torso break end end) end)

P.S: Taslem this isn't spam.

0
Well, he's right. It's not spam... Though I think someone else would be more qualified to answer this question, I stink when it comes to CFrames. M39a9am3R 3210 — 9y

2 answers

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

First, that doesn't make sense. The z coordinate of Size isn't a position -- it's a length.

If you mean you want Lazor to stretch between the character's torso and where they are pointing, you could do this:

Lazor.Size = Vector3.new(2, 2, (from - to).magnitude )
-- As long as the distance from from to to.
Lazor.CFrame = CFrame.new(  (from + to) / 2, to )
 -- from the middle, looking at an end

Then from would be Character.Torso.Position and to would be...

Not mouse.Target.Position. mouse.Target is a part. Its position is the center of that part, not where you are pointing (so it would be very far away for large objects).

Use mouse.Hit.p to get the position the mouse is hovering over.

0
Ooh, I never thought of using "(Position + Position) / 2", but now that I think about it, it makes perfect sense. Adding two numbers and halving the sum returns the number between them, so I do not know why I did not apply that logic to vectors. Diitto 230 — 9y
Ad
Log in to vote
0
Answered by
Diitto 230 Moderation Voter
9 years ago

Use Mouse.Hit.p or Mouse.Target.Position. And as for your script, there are a few incorrect things, like the size configuration and the position of the laser.

local Player=Game:service'Players'.localPlayer;
local Character=Player.Character;
local Mouse=Player:getMouse();
Mouse.Button1Down:connect(function()
    pcall(function()
        local Distance=(Character.Torso.Position - mouse.Hit.p).magnitude;--// The distance apart
        local Lazor = Instance.new("Part",workspace)
            Lazor.Size = Vector3.new(11,2,Distance) --   I need it for this...
            Lazor.Name = "Lazor"
            Lazor.Position = CFrame.new(Character.Torso.Position, mouse.Hit.p) --// Starts at the torso while pointing at the position, goes halfway there.
            * CFrame.new(0,0,distance / 2);--// BlueTaslem's method with adding the positions together and dividing it works as well.
        Instance.new('Explosion',Workspace).Position = mouse.Hit.p;
    end)
end)

Answer this question