Vaulting "Physics" - Movement System

Hey guys!

I’m gonna just keep it simple, I’m trying to make a vaulting system which is going kinda good…

[Besides the actual physics part]

I’m trying to achieve this:
[Taken from Jujutsu Shenanigans]

External Media

Yet this is what i have:

External Media

The physics is just completely horrible, [I literally have NO idea what i’m doing]. I’ll be explaining the 3 beams you see on the character, which are apart of the detection system.

There’s a runservice stepped function, with a ray between a attachment [slightly below HRP.Position], to 2 studs infront of it.

If that ray hits something, another two rays will start, 55 degrees upwards, and downwards. [Pretty sure we can use these raycasts for the physics part]

If the Second Ray hits nothing, then it is allowed to vault. I’m not sure if this is the best way to do it, but i tried.

The code is just a rough example of what im doing, just removed some stuff that aren’t related / removed it from a module:


local LocalPlayer = game:GetService("Players").LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local CurrentCamera : Camera = workspace.CurrentCamera
local Humanoid : Humanoid = Character:FindFirstChildOfClass("Humanoid")
local RootPart : Part = Character:FindFirstChild("HumanoidRootPart")
local Animator : Animator = Humanoid:FindFirstChildOfClass("Animator")

local RaycastParams_ = RaycastParams.new()
RaycastParams_.FilterType = Enum.RaycastFilterType.Include
RaycastParams_.FilterDescendantsInstances = {workspace.Map}
_G.MapParams = RaycastParams_

local VaultOffset = 2
local VaultOffset2 = 4

local RootBeam : Beam = RootPart.Beam
local Raycast1Attc = RootPart.Raycast1 

function MovementForce(TargetPart, Velocity, TargetVelocity, Duration, callback)
	local BodyVelocity = Instance.new("BodyVelocity", TargetPart)
	BodyVelocity.MaxForce = Vector3.new(40000, 40000, 40000)
	BodyVelocity.P = 40000
	BodyVelocity.Name = "MovementForce"
	BodyVelocity.Velocity = Velocity

	local velocityTweenProperties = { Velocity = TargetVelocity }
	game:GetService('TweenService'):Create(BodyVelocity, TweenInfo.new(Duration / 3), velocityTweenProperties):Play()

	task.delay(Duration, function()
		BodyVelocity:Destroy()
		if callback then callback() end
	end)
end

game:GetService("RunService").RenderStepped:Connect(function(Delta)
	local RootRaycast = workspace:Raycast(RootPart.Raycast1.WorldPosition, Raycast1Attc.WorldCFrame.LookVector * VaultOffset, RaycastParams_)
	local SecondRay
	local ThirdRay
	local State = Humanoid:GetState()
	local Can_Vault = false

	if RootRaycast then
		SecondRay = workspace:Raycast(Raycast1Attc.WorldPosition,  (Raycast1Attc.WorldCFrame * CFrame.Angles(math.rad(55), 0, 0)).LookVector * VaultOffset2, RaycastParams_)
		ThirdRay = workspace:Raycast(Raycast1Attc.WorldPosition, (Raycast1Attc.WorldCFrame * CFrame.Angles(math.rad(-55), 0, 0)).LookVector * VaultOffset2, RaycastParams_)

		if not SecondRay then
			Can_Vault = true
		end
	end


	if Can_Vault
		and not Character:GetAttribute("Vaulting")
		and Character:GetAttribute("Sprint")
		and (State ~= Enum.HumanoidStateType.Freefall and State ~= Enum.HumanoidStateType.Jumping) then
		Character:SetAttribute("Vaulting", true)


		MovementForce(
			RootPart, RootPart.CFrame.LookVector * 20 + Vector3.new(0, 17.5, 0), -- Start Velocity
			RootPart.CFrame.LookVector * 22,  -- End Velocity
			0.3,  -- Duration
			function()  -- Call back [once ready]
				Character:SetAttribute("Vaulting", false) 
				Character.Torso.CanCollide = true
			end)	


		Character.Torso.CanCollide = false
	--	LoadedAnimations.Vault["Track" .. math.random(1, 4)]:Play() [not sending the load animations code since it's basically useless in here]
	end

end)


also pls dont harass me for using _G. thx :money_mouth_face: [this is directed to u @netheround]

i hate roblox and this physics