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

Can you change lookVector?

Asked by 9 years ago

I made a script, and it had an error, someone on SH helped me, but now I realized that the front of the block, is not the front of the tool! Can I change the lookVector (subtract or add 90 degrees to it)? Here is my script

wait(1)
script.Parent.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
--  local animation = script.Slash
--  local plyr = script.Parent.Parent.Name
--  local char = workspace:FindFirstChild(plyr)
--  local anim = char.Humanoid:LoadAnimation(animation)
--  anim:Play()
    local bullet = Instance.new("Part")
    bullet.FormFactor = "Custom"
    bullet.Size = Vector3.new(0.5,0.2,0.2)
    bullet.BrickColor = BrickColor.new("Toothpaste")
    bullet.BackSurface = "SmoothNoOutlines"
    bullet.BottomSurface = "SmoothNoOutlines"
    bullet.FrontSurface = "SmoothNoOutlines"
    bullet.LeftSurface = "SmoothNoOutlines"
    bullet.RightSurface = "SmoothNoOutlines"
    bullet.Velocity = script.Parent.Part1.CFrame.lookVector * 100 --this part
    bullet.TopSurface = "SmoothNoOutlines"
    bullet.Parent = workspace
    bullet.Position = script.Parent.Handle.Position
    bullet.Transparency = 0
    bullet.CanCollide = true
    --local speed = script.Speed:clone()
    --speed.Parent = bullet
    local damage = script.DamageScript:clone()
    damage.Parent = bullet
    print("HALLAAA")
    end)
end)

Please help!!! Thank you!!!

2 answers

Log in to vote
3
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

You cannot 'change' lookVector itself, because it's read-only. But you can do some math to get the direction of other faces. lookVector is the direction of the Part's FrontFace, so using this we can get the other faces pretty simply;

--Forward
part.CFrame.lookVector

--Backward (negative or 'opposite' of lookVector)
-part.CFrame.lookVector

--Left (gets the lookVector of a CFrame rotated 90 degrees to the left)
(part.CFrame * CFrame.Angles(0, math.rad(90), 0)).lookVector

--Right (same as left, but negative. thus the opposite of left, which is right.)
-(part.CFrame * CFrame.Angles(0, math.rad(90), 0)).lookVector
Ad
Log in to vote
0
Answered by
Hexcede 52
9 years ago
partToRotate.CFrame = partToRotate.CFrame * CFrame.Angles(0, math.rad(90), 0) -- the y axis rotates the front of the part a certain ammount. Change 90 to -90 if it isnt the right direction.
0
Why did I get a downvote? Hexcede 52 — 9y
0
Nope, didn't work, thanks tho yogipanda123 120 — 9y
0
Do you have any idea on my question? It is at the top about. Hexcede 52 — 9y
0
nope, wasn't me, but i upvoted so it should be back at 0 yogipanda123 120 — 9y
0
thanks! Hexcede 52 — 9y

Answer this question