I’m working on an M1 combat system that uses rays to detect objects in front of the player to calculate the distance the player needs to move in order to not go through the wall or fling themselves. Everything is going well, but I was wondering how I could implement more space between the player and the object if an object is detected while the ray is casted. I will provide pictures to further support this question.
SCRIPT:
local MAX_DISTANCE = 7
local ray = Ray.new(HumanoidRootPart.Position, HumanoidRootPart.CFrame.LookVector * MAX_DISTANCE)
local part, position = workspace:FindPartOnRay(ray, HumanoidRootPart.Parent)
MakeRayVisible(ray)
local BodyPosition = Instance.new("BodyPosition", HumanoidRootPart)
BodyPosition.Name = "Client"
BodyPosition.D = 500
BodyPosition.MaxForce = Vector3.new(10000, 10000, 10000)
BodyPosition.P = 3000
BodyPosition.Position = position
Here are some pictures of what I need done:
Current situation:
https://gyazo.com/ecc49d63031ef4e7dc0a8d9f747831ec
https://gyazo.com/671a81f741e24bc566a3fda76e7caeb9
What I want:
https://gyazo.com/ef635dc8134e41e56455530e58f0feea