a one stud ray will not go very far, try casting it farther
This piece of code is just detecting to see if there even is a part in front of the player, as stated above in the comment.
This works fine and is not relevant to the issue I’m currently having.
try setting the position of a part at the origin.
I believe it’s this. The UpVector of NewRaycastOrigin will always be 0, 1, 0, so the above line will make the raycast go upwards. The problem is, the raycast’s origin (NewRaycastOrigin) is already above the object, so the ray will just fire into the sky.
To make it go downwards, change it to
local NewRaycastDirection = -NewRaycastOrigin.UpVector * 5
Or
local NewRaycastDirection = NewRaycastOrigin.UpVector * -5
Yea, I want the ray to go upwards, NewRaycastOrigin isn’t actually above the part. It’s right at the top of it. If you take a look at the diagram I included in the Code tab, there’s an example of what TrueHeight represents.
Although what you’re saying is correct, it would still work if I went downwards from 5 studs up. However as I said before, I suspect the error I’m facing has something to do with the actual position/cframe not actually being where its supposed to be. (if that makes sense)
I think you’ll find some help in visualizing the raycast. Also, can you explain what’s not working specifically?
I’ve tried visualizing the raycast and it seemed to pointing to a completely different position. Although I’ll definitely try once again with the method you provided.
The problem I’m currently having is either:
- The Raycast isn’t actually starting at the correct origin
- The Raycast isn’t pointing towards the right position (In this case the DIRECTION would be messing everything up)
- Both of the above
Essentially, the Raycast doesn’t seem to be correctly detecting if there is a part above another part, even when I manually put something right ontop of each other. Sometimes it’ll work depending on which side of the wall I’m facing, so that’s why I’m assuming the Vectors aren’t actually where I want them to be.
I just noticed, you probably want to move the Y position away from the center of the world
local NewRaycastOrigin = CFrame.new(
Character.HumanoidRootPart.Position.X,
Character.HumanoidRootPart.Position + TrueHeight,
Character.HumanoidRootPart.Position.Z
)
Does the visualization look any different?
Nah, this should still work. TrueHeight is the Y position/height mix of the part that I want the player to vault over. It doesn’t represent the center of the world since the x and y axis is still the x and y of the Player’s HumanoidRootPart. Correct me if I’m wrong though, I may not be understanding properly.
The visualization doesn’t seem to be working since I’m adding the position to it, this just makes the origin extremely high up in the world instead of at the top of the part I want to vault over.
Sending a gif of my testing so you can take a look for yourself.
nil
As you can see, there’s some issue with my origin / direction since it seems to be working differently depending on which side I try to vault on.
I should clarify that I haven’t changed anything. So I still have the same code as what I provided above.
the ray is casting up but it is not detecting anything. move the origin of the ray in the direction of the hrp lookvector
do something like
* CFrame.new(hrp.CFrame.lookVector * 3)
Seems like I’m still having the same issue as before.
when you see the ray, does the origin change to inside the part? or is it still on the outside like in the image I showed above
Still on the outside for some reason.
- CFrame.new(hrp.CFrame.lookVector * 10)
How about when you put it as an even bigger number. Does it make a difference?
Apart from making the Raycast longer, it doesn’t make a difference.
I haven’t looked at your code yet but I have found that a diagonal ray from rootpart (or a couple studs higher. Depending on gravity and jump strenth) to a point, in a ratio of, something like, 5 up and 1 forward (Test it) works pretty well for; CheckIfJumable and covers the IsGapTooSmall problem too.
(Oh, also, instead of drawing the initial ray just Forward, or drawing two rays; sometimes I draw the ray at an angle from, like, the bottom right of AI’s Torso to the top/left)
And you should ALWAYS draw the ray, while debugging too. It just makes things so much easier…
I only just changed this to use the new rays, so it might have errors, but it seems to work fine so far…
(Throw as much logic as you can at the problem: You can check the size and position of the Part, which you hit in the first place to figure out what’s going on too, and decide what to do next…)
function DrawRay(origin, direction) -- origin is a point. Direction is a vector3; it's magnitude = length
local hitPart
local Position = origin + direction -- Destination position, unless hit a part
local Normal
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {bin.Parent} -- whatever model this is in...
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist -- don't hit any parts of us
local raycastResult = workspace:Raycast(origin, direction, raycastParams)
if raycastResult then
hitPart = raycastResult.Instance
Position = raycastResult.Position
Normal = raycastResult.Normal
end
if true then --Graphics for debugging
local RayPart = Instance.new("Part", bin.Parent) -- Add graphics to blacklist
if hitPart then -- Black if hit something
if true then -- You can check which call this cast is for and change the color
RayPart.BrickColor = BrickColor.new("Black") --Set its color.
else
RayPart.BrickColor = BrickColor.new("Bright red") --Set its color.
end
else -- White color if no hit
if true then
RayPart.BrickColor = BrickColor.new("White") --Set its color.
else
RayPart.BrickColor = BrickColor.new("Olive") --Set its color.
end
end
RayPart.Transparency = 0.3 --Set its transparency.
RayPart.Anchored = true --Set whether it will fall or not.
RayPart.CanCollide = false --Set whether people can walk though it or not.
RayPart.formFactor = Enum.FormFactor.Custom --Make it so it can be small.
local Distance = (Position-origin).magnitude --Find the distance between the hit and the torso.
local PercentLeft = (1-Distance/(direction).magnitude)+0.2 -- What part of directioon did we not make. Make ray fatter.
RayPart.Size = Vector3.new(.4, PercentLeft, Distance) --Set its size to the distance.
RayPart.CFrame = CFrame.new(Position, origin) * CFrame.new(0,0,-Distance/2) --Move it halfway.
game.Debris:AddItem(RayPart,5) --Add it to the debris.
end -- Graphics
return hitPart, Position, Normal
end
Appreciate the advice, I’ve been doing just that so far and I’ve currently isolated the problem.
For some reason, any changes to the origin or the direction makes the vector/cframe relative to the world instead of the object.
For instance, in my code the origin now looks like this:
local NewRaycastOrigin = CFrame.new(Raycast.Position.X, TrueHeight, Raycast.Position.Z)
Now this is all fine and works as I intend, but anything I either multiply a CFrame to this or change any of the .X, .Y, .Z parameters it completely switches to the world space.
Any idea why? I’m completely stumped.
I was able to fix the Raycast not consistently aligning with the wall depending on which side I’m facing, however that’s all the progress I’ve made.
Debugging info:
Any time the ray detects a part, it makes it glow for a brief second.
Overhangs are easily found since the ray is aligned to the wall beneath it. However I need the red brick to glow in this case to indicate that the space in-between the part and the red brick is too small to vault over. I’ve added a gif so it’s easier to see.
nil
No, I understand not what you are saying.
Also, why are you drawing a ray after jumping?
If after getting a false on WalkForward; shoot a diagonal one from like the Head or something… If you get another false, (like it looks like you should there), then you are not gonna be jumping anyway; AI should be walking round the wall, no?
I would strongly suggest a diagonal ray for jumping. I don’t mix well with math, so just shoot rays from point to point…)
This is a really old Rat-casting, wall-hugging AI, before PathFind, or new RayCast but I am pretty sure that it works. Maybe you can salvage some parts from it
Oh, it might check for not walking off cliffs too, which is set really low, so won’t jump off anything, really…, and goes around.
The reason I’m jumping is because that’s how vaulting works, if the player jump and finds a valid ledge. They will hop over it. My entire issue right now is that I don’t want a player hopping over a ledge IF there is a part right on top of it OR if there is a part too close to the top.
I’ve already provided examples in the “Clarification” tab in the original post.
I’ll attach a gif of what vaulting is SUPPOSED to look like.
nil