I'm working on a 2D Platformer framework with a custom player and would like to create a function that returns true if the player is close to like floor, (Like
if (player.CFrame.p - position).magnitude <= 3 then end
) but I can't get a ray to be directly below the brick I'm using as a player, it's always at a slant. Does anyone know how I would get the ray to be directly perpendicular from the brick to what's below it? My current code:
plr = script.Parent
ray = Ray.new(plr.CFrame.lookVector, (plr.CFrame.lookVector + Vector3.new(0,math.rad(-180),0)).Unit*300)
hit, position = game.Workspace:FindPartOnRay(ray)
print(hit)
print(position)
--Test ray visual
local distance = (position - plr.Position).magnitude
local rayPart = Instance.new("Part", game.Workspace)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright red")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position, plr.Position) * CFrame.new(0, 0, -distance/2)

1 comment
Post your new code please