How to get orientations character with .Position, since a raycast requires vector3

So im firing a ray benith my character, but the problem is if i turn my character around the circle around me stays the same, so it looks as if the ability is casted side ways (as show in the video)

code:

for h = 1, numCircles do

		local numParts = rnd:NextInteger(30, 35)

		for i = 1, numParts do

			local rock = Instance.new("Part")

			local rx = pos.X + rnd:NextNumber(-1,1)
			local rz = pos.Z + rnd:NextNumber(-1, 1)
			local lookAt = Vector3.new(rx, pos.Y, rz)

			local orientation = Vector3.new(rnd:NextNumber(-60, 60), rnd:NextNumber(-60, 60), rnd:NextNumber(-60, 60))
			local lv = CFrame.new(pos, lookAt).LookVector
			local position = pos + (lv * radius * math.clamp(h/numCircles, 0.4, 1))
			local cf = CFrame.new(position, pos + lv + orientation)

			local rockSize = Vector3.new(rnd:NextNumber(1.5, 2.2), rnd:NextNumber(1, 2), rnd:NextNumber(1.4, 2))
			rockSize *= h/numCircles

			local rp = RaycastParams.new()
			rp.FilterDescendantsInstances = {workspace["Effects"]}
			local floorRay = workspace:Raycast(cf.Position + Vector3.new(0, 3, 0), position - Vector3.new(0, 100, 0), rp)
				
			if floorRay and floorRay.Instance.Anchored then
				local colour = floorRay.Instance.Color
				local mat = floorRay.Instance.Material

				rock.Size = Vector3.new(0, 0, 0)
				rock.Position = floorRay.Position
				rock.Orientation = orientation
				rock.CanCollide = false
				rock.Anchored = true
				rock.TopSurface = Enum.SurfaceType.Smooth
				rock.Color = colour or Color3.fromRGB(83, 86, 90)
				rock.Material = mat or Enum.Material.Slate

				rock.Parent = workspace["Effects"]

				TweenModule.obj(rock, "Quad", "Out", 0.2, {Size = rockSize})

				task.spawn(function()
					task.wait(5)

					local fallTween = ts:Create(rock, rocksTI, {Position = rock.Position - Vector3.new(0, rock.Size.Y/2, 0)})
					fallTween:Play()
					fallTween.Completed:Wait()

					rock:Destroy()
				end)
			end
		end

		task.wait()
	end

video:

2 Likes

You can use CFrame and get its position.

Can you show me how to do it, Raycast requires vector 3, so i wouldnt know how to do that.

Position is a CFrame property, for example:

local CF = CFrame.new(1, 1, 1) --CFrame
local Position = CF.Position --Vector3

print(Position) -- 1, 1, 1

image
I used root.CFrame.Position and its still as if im not in the centre of the circle

Then try LookVector.

For example:

local RaycastDistance = 100 -- Raycast distance is 100
local Origin = root.CFrame.Position
local Direction = Vector3.new(-0, -1, -0) * RaycastDistance -- LookVector (for floor) * Distance
workspace:Raycast(Origin, Direction, rp)

Sorry for late reply, I tried to make a raycast directly to the floor with this.

I believe the code below should work no matter your rotation.

local floorRay = workspace:Raycast((cf * CFrame.new(0, 3, 0)).Position, position - Vector3.new(0, 100, 0), rp)

I tried to make a raycast directly to the floor with making look vector 0, -1, 0 and multiply it with the distance