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

How do you make a brick change it's rotation to the same as the object that hit it?

Asked by 6 years ago

Hi, I am getting a error, it says that rightVector can't be assigned to. Any help?

script.Parent.Parent.Touched:connect(function(h)
    script.Parent.Parent.CFrame.rightVector = h.CFrame.rightVector
end)

3 answers

Log in to vote
0
Answered by 6 years ago

Try this, perhaps. This should take only the rotation of part h and apply it.

script.Parent.Parent.Touched:connect(function(h)
    local hCFrameRotationOnly = h.CFrame - h.CFrame.p
    script.Parent.Parent.CFrame =
        hCFrameRotationOnly + script.Parent.Parent.CFrame.p
end)
0
Works thanks! LennonLight 95 — 6y
Ad
Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
6 years ago

RightVector is a read-only value, and thus cannot be changed. Something like this might help instead:

script.Parent.Parent.Touched:Connect(function(h)
    local pos = script.Parent.Parent.Position
    local lookAt = pos + h.CFrame.lookVector
    script.Parent.Parent.CFrame = CFrame.new(pos,lookAt)
end)
0
I should make some clerifications, I want it to only be the X Axis. LennonLight 95 — 6y
0
Clarifications* LennonLight 95 — 6y
0
Also, doesn't work LennonLight 95 — 6y
Log in to vote
0
Answered by 6 years ago

Hey LennonLight,

The way that I am about to demonstrate before you is a pretty famous and easy way to change a part's direction that it faces. Well, I will show it to you below and explain it line by line. Better to demonstrate and explain at the same time rather than just say how to do it.

----Example----

local part = script.Parent; -- The part 
local parts_to_not_touch = { -- Dictionary with the names of the parts that it shouldn't react towards.
    ["Baseplate"] = true;
}

part.Touched:Connect(function(obj) -- Declares an anonymous function connected to a Touched event.
    if not parts_to_not_touch[obj.Name] then -- If statement checking if the obj's name isn't any stored in the table, so it can prevent reactions to those parts.
        part.CFrame = CFrame.new(part.Position, obj.Position); -- Changes the CFrame by keeping the part's original position and sets the direction that the part is facing to the object that it touched.
    end -- end for the if statement
end) -- end for the function

I hope that I helped, and have a nice day.

Thanks,

~~ KingLoneCat

0
He doesn’t want to point the part to face the object that touched, but rather point the part in the same direction and have it face the same way as the object that touched. mattscy 3725 — 6y

Answer this question