【发布时间】:2018-03-11 10:47:13
【问题描述】:
我一直在寻找一种方法来获取鼠标的坐标,这样我就可以将一部分传送到鼠标上进行游戏。我发现的只是 GetMouse() 我不太明白。顺便说一句,我是 rolblox lua 的新手。
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
MousePos = Mouse.Hit
print (MousePos)
【问题讨论】:
我一直在寻找一种方法来获取鼠标的坐标,这样我就可以将一部分传送到鼠标上进行游戏。我发现的只是 GetMouse() 我不太明白。顺便说一句,我是 rolblox lua 的新手。
Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
MousePos = Mouse.Hit
print (MousePos)
【问题讨论】:
好的,首先我假设您的代码在本地脚本中(应该是这样)。 ':GetMouse()' 只是获取玩家的鼠标。鼠标具有不同的属性和事件。
您可以通过以下方式获取鼠标的CFrame:
local MouseCFrame = Mouse.Hit
CFrame 值不仅仅包含鼠标在现实世界空间中的位置。 CFrame 值包含位置和旋转。我们可以通过以下方式获得职位:
local MousePosition = MouseCFrame.p
我们使用 CFrame 值的 'p' 属性来获取该 CFrame 值的位置。很有用。所以,你的最终代码是:
local Player = game.Players.LocalPlayer -- Also, I noticed you weren't using 'local' to define your variables. Use that, as it sets the variable apart from a global variable.
local Mouse = Player:GetMouse()
local MouseCFrame = Mouse.Hit
local MousePosition = MouseCFrame.p
print (MousePosition)
希望我能帮上忙! :)
【讨论】: