You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
My race game has a car that needs a proximity sensor to scan around nearby objects and detects how near they are. It scans back and forth along the axis. Shooting out a ray 70 studs forward -
What is the issue? Include screenshots / videos if possible!
The ray direction is in 0,0,0 -
What solutions have you tried so far?
I tried tinkering with the RayDirection values. It’s hard though. I printed the raydirection and the position says to be 0
I’ve also tried removing CFrame.new but like then it errors “malformed cframe value”
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local rs = game:GetService("RunService")
local t = 0
local sweepingforward = false
rs.Stepped:Connect(function()
if t < 180 and sweepingforward == false then
t = t + 1
local rayDirection = (CFrame.new( script.Parent.CFrame.LookVector + Vector3.new(0,0,70) ) * CFrame.Angles(0,math.rad(t),0)).p
game.Workspace.glowt.Position = rayDirection
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {caster.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local objpos = raycastResult.Position
local pos = script.Parent.Position
local vels = (script.Parent.Velocity - hitPart.Velocity).Magnitude
print(vels)
rate = (objpos-pos).Magnitude*(vels / 0.1)
print(rate)
end
if t > 179 then
sweepingforward = true
end
end
if t > -180 and sweepingforward == true then
t = t - 1
local rayDirection = (CFrame.new( script.Parent.CFrame.LookVector + Vector3.new(0,0,70) ) * CFrame.Angles(0,math.rad(t),0)).p
game.Workspace.glowt.Position = rayDirection
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {caster.Parent}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local hitPart = raycastResult.Instance
local objpos = raycastResult.Position
local pos = script.Parent.Position
local vels = (script.Parent.Velocity - hitPart.Velocity).Magnitude
print(vels)
rate = (objpos-pos).Magnitude*(vels / 0.1)
print(rate)
end
if t < -179 then
sweepingforward = false
end
end
end)