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

Getting the direction of a part help?

Asked by
NotSoNorm 777 Moderation Voter
8 years ago

Alright, So apparently I'm supposed to get the direction of a part then find part on ray, but how am I getting the direction of a part with position?

'Players.Player.Backpack.LocalScript:21: attempt to index field '?' (a nil value)'

local walls = game.Workspace.Walls:GetChildren()
local chartorso = game.Players.LocalPlayer.Character.Torso
local lowname = nil
local lowest = 20

for i = 1, #walls do
    walls[i].Name = "Wall"..i
end

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.E then
        for i,v in pairs (walls) do
            if math.ceil((chartorso.Position-v.Position).magnitude) < lowest then
                lowest = math.ceil((chartorso.Position-v.Position).magnitude)
                lowname = v.Name
            end
        end
        print(lowname)
        print(chartorso.Position)

        local ray = Ray.new(chartorso.Position, walls[lowname].Position * 300)

        local hit, position = game.Workspace:FindPartOnRay(ray)

        for i = 1, #walls do
            walls[i].BrickColor = BrickColor.new("Smoky grey")
        end
        game.Workspace.Walls[lowname].BrickColor = BrickColor.Green()
        lowest = 20
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

1 answer

Log in to vote
0
Answered by 8 years ago

You can't with position however you can with CFrame. Don't ask me how though, I am not quite that advanced in math. The standard Vector3 value that you use with CFrame.new() is a tip of the ice berg. CFrame can also give current rotation as well as it's position. I would look it up on the wiki as it explains the rotation matrix a bit more.

0
I think I misunderstood you question. You are looking for how to get the direction of a part compared to the position of another object aren't you. BobserLuck 367 — 8y
0
ye NotSoNorm 777 — 8y
Ad

Answer this question