- What do I want to achieve? I want to make it to rotate automatically according to the part where’s the rays hit. basically, Laser Pointer using raycasting
-
What is the issue?
try this
local function CreateLazer(StartPoint : Vector3, EndPoint : Vector3)
if not StartPoint or not EndPoint then return end
local Distance = (StartPoint - EndPoint).Magnitude
local Bullet = Instance.new("Part")
Bullet.CastShadow = false
Bullet.CanCollide = false
Bullet.Anchored = true
Bullet.Size = Vector3.new(0.1, 0.1, Distance)
Bullet.CFrame = CFrame.new(StartPoint, EndPoint) * CFrame.new(0, 0, -Distance / 2)
Bullet.Parent = workspace
end
didn’t worked
ignore this : Post must be at least characters
Well, did you replace what the variable “blood” referenced? And I’m assuming you changed the variable name as well, correct?
I didn’t i just use the same concept as used in that. it rotates but it doesn’t seems to be rotate the y-axis on cylinder
Here, I changed it a bit to rotate properly:
local blood = workspace.Blood
local rpm = RaycastParams.new()
rpm.FilterType = Enum.RaycastFilterType.Blacklist
rpm.FilterDescendantsInstances = {blood}
local raycasts = {}
for i = -1, 1, 2 do
table.insert(raycasts, workspace:Raycast(blood.Position,Vector3.new(0, 0, i)*5, rpm))
table.insert(raycasts, workspace:Raycast(blood.Position,Vector3.new(i, 0, 0)*5, rpm))
table.insert(raycasts, workspace:Raycast(blood.Position,Vector3.new(0, i, 0)*5, rpm))
end
local closest
local closestmag = math.huge
for i,v in pairs(raycasts) do
if v then
if closestmag > (blood.Position-v.Position).Magnitude then
closest = v
closestmag = (blood.Position-v.Position).Magnitude
end
end
end
if closest then
blood.CFrame = CFrame.lookAt(blood.Position, closest.Position) * CFrame.Angles(math.rad(0),math.rad(90),math.rad(0))
end
didn’t worked with 90 but seems like 180 might be
I’m not sure why 90 didn’t work, it worked for me. Could you show me what it looked like before adding the rotation bit?
without Rotation
by the way didn’t worked with 180 either
Try using a different angle:
blood.CFrame = CFrame.lookAt(blood.Position, closest.Position) * CFrame.Angles(math.rad(0),math.rad(0),math.rad(90))
or
blood.CFrame = CFrame.lookAt(blood.Position, closest.Position) * CFrame.Angles(math.rad(90),math.rad(0),math.rad(0))
didn’t worked either
ignore this : Post must be at least characters
could you provide me the laser you are using for this?
local plr = plrs.LocalPlayer
local mouse = plr:GetMouse()
local chr = plr.Character or plr.CharacterAdded:Wait()
local POS = game.ReplicatedStorage.POS:Clone()
POS.Parent = workspace
while task.wait() do
local rayprayms = RaycastParams.new()
rayprayms.FilterType = Enum.RaycastFilterType.Blacklist
rayprayms.FilterDescendantsInstances = {chr}
local pos = script.Parent.Handle.Position
local ray = workspace:Raycast(pos, (mouse.Hit.Position-pos)*1.1, rayprayms)
if ray then
POS = game.ReplicatedStorage.POS:Clone()
POS.Parent = workspace
print(ray.Distance)
--POS.Orientation = ray.Instance.Orientation*2
POS.Position = ray.Position
POS.CFrame = CFrame.lookAt(POS.Position, chr:FindFirstChild("HumanoidRootPart").Position)* CFrame.Angles(math.rad(90),math.rad(0),math.rad(-0))
end
end
Could you send the POS
model/cylinder so I can see/check why this won’t rotate properly?
Ok, actually, I didn’t need the model. The problem is that you are having it look towards the HumanoidRootPart.
local plr = plrs.LocalPlayer
local mouse = plr:GetMouse()
local chr = plr.Character or plr.CharacterAdded:Wait()
local POS = game.ReplicatedStorage.POS:Clone()
POS.Parent = workspace
while task.wait() do
local rayprayms = RaycastParams.new()
rayprayms.FilterType = Enum.RaycastFilterType.Blacklist
rayprayms.FilterDescendantsInstances = {chr}
local pos = script.Parent.Handle.Position
local ray = workspace:Raycast(pos, (mouse.Hit.Position-Vector3.new(0,-1,0)).Unit*1.1, rayprayms)
if ray then
POS = game.ReplicatedStorage.POS:Clone()
POS.Parent = workspace
POS.Position = ray.Position
POS.CFrame = CFrame.lookAt(POS.Position, ray.Position) * CFrame.Angles(math.rad(90),math.rad(0),math.rad(-0))
end
end
Edit: I’m going to be going to sleep now, so I won’t be able to answer any further questions till I wake up.