I’m trying to make a vaulting system but having trouble with how to do it.
The goal is to create a raycast from the head offset by the rootParts lookvector that’s aiming down until it reaches half the characters body. It checks if the result’s normal is facing downwards and if not it takes the height difference between the result’s position and the player and so on.
First off my raycast is not detecting anything and second I’m not sure if the math is correct
--this is wrong, this should be multiplication, not addition.
local result = workspace:Raycast(rayOrigin, rayDirection + rayLength, raycastParams)
Regarding Humanoid.Height, just add all of the Y components of the (Upper&Lower)Torso, (Upper&Lower)Leg and the head together; or if you use the default roblox rig you can just use 6 as the height.
I don’t understand what you’re trying to do, what do you want to happen when the user presses space?
The reason why your ray isn’t detecting anything is probably because your ray is too short.
This is what HKcat says : The UTG vault system works like this:
It spawns a raycast from the head offset by the humanoid root parts look vector aiming straight down until it reaches half the characters body.
If it hits something, it checks if the normal is facing downwards.
If it isn’t, it takes the height difference between the result’s position and the player. This number is then multiplied by a growth factor and added onto a separate static vault strength. Then, you apply an upwards force to the player with that combined boost strength. This lets you have a minimum vault height and high vaults by vaulting a bit lower from the edge.
To increase the speed, there is a separate force applied in the direction the player wants to go, think WASD. You get a WASD unit vector from the players humanoid.
The air movement in UTG has deccel and accel so it’s a bit harder to move, but with the boost sending you directly in the direction you want to go, it lets you turn a bit easier as well .you only need to create 1 raycast facing down when you press space.
Oh thank you, anyway, I looked at the post and it seems like there’s already a solution. I don’t know why you aren’t using that one. The only reason I can think of is because it only uses one raycast. You can also have one raycast if we just check where the upper bound of your target part is.
I got this working:
local user_input_service = game:GetService "UserInputService"
local replicated_storage = game:GetService "ReplicatedStorage"
local players = game:GetService "Players"
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root = character.PrimaryPart :: BasePart
local head = character:WaitForChild "Head" :: BasePart
local humanoid = character:FindFirstChildOfClass "Humanoid"
local can_vault = true
local function vault()
if not can_vault then return end
local params = RaycastParams.new()
params.FilterDescendantsInstances = {character}
params.FilterType = Enum.RaycastFilterType.Exclude
local result = workspace:Raycast(root.Position, root.CFrame.LookVector * 6, params)--adjust range
if not result or not result.Instance or not result.Instance:IsA "BasePart" then return end
can_vault = false
local part = result.Instance :: BasePart
local diff = (head.Position.Y + head.Size.Y / 2) - (part.Position.Y + part.Size.Y / 2)
if diff < 0 then return end --head is below part's upper bound
--move direction is a unit vector, no need for .Unit
root:ApplyImpulse((humanoid.MoveDirection * 60 * root.AssemblyMass) + Vector3.new(0, 60 * root.AssemblyMass * diff))
task.wait(0.22)
can_vault = true
end
user_input_service.InputBegan:Connect(function(input, process)
if process or input.KeyCode ~= Enum.KeyCode.Space or input.UserInputState ~= Enum.UserInputState.Begin then return end
vault()
end)
Here’s an implementation, that also only uses one raycast.
I don’t know why you’d check the normal vector, so I deleted it.
Hope this helps.
(you might have to change the values because sometimes it launches me to space, so maybe 40 instead of 60 idk.)
Hey, so it works which I thank you for but there is a bug and don’t know what’s causing it. https://gyazo.com/40a6a9ea8c7589fcaf114d3989dc7a3a
So the code is working but then when I try to vault over something I can’t it stops working.
I can’t seem to reproduce your issue, the only situation where I don’t go flying is when I’m too close to the part, but that’s because the impulse makes me slam into the wall and bounce back a bit, it still works.
can you maybe add some print statements and check what the upper bounds of the head and part, and the difference between them were when it stopped working?
(video of it working, but also sometimes bouncing backwards)
edit: maybe the target part is below the center of the root and therefore not being hit by the ray?
The issue appears when I try to vault over something a bit higher so like this :
It works fine until I try to vault over it and then it stops working for no reason. Prints aren’t working or anything. https://gyazo.com/08263c940723e520c39916a763bab0f4
ohhh, well that’s because the upper bound of your head is probably like 0.0001 stud lower than the upper bound of your part, because of this, nothing happens because the result of the difference is negative. you can maybe tolerate some negativity, by doing this:
if diff < -1 then --tolerate more negative nums
but watch out, you then also have to take the absolute value in applyimpulse
you can see if the upper bound of your head is lower than the upper bound of your part by removing your hair, and checking if the head is still above your part.
That seems to have fixed the problem for the slightly higher part but the main issue is that when I try to vault or even just pressing space over something that has the diff lower than -1 the code bugs out again. https://gyazo.com/ccffede7bde76eb898f303ff9c30ab54
I managed to fix it with this : if diffrence < -1 then can_vault = true return end . Just had to set it to true so I could vault again. Anyway thanks for the help