Im trying to add a walking system to a pet system.
The System is detecting the ground but not other inserted Parts, like a new created one (even if its server sided)!
And im worried how i can fix the problem
You have a variable named blacklist, which is supposed to be the RaycastParams. You haven’t provided what blacklist actually refers to (specifically the code). There could be something wrong with your parameters.
Alternatively, make sure that your parts don’t have query disabled (although they shouldn’t be considering they appear to be solid).
I guess everything there looks right. Perhaps the Vector3 operation is the issue. You’re using multiplication rather than addition. Unlike CFrames, multiplication with Vector3 will multiply the value of the given axis, or all if only using a single number. That means your Y axis is being multiplied by 10 instead of just having an offset of 10 studs up. I don’t see any other issues with the code you’ve shown so far.
It’s hard to say without seeing all of the relevant code. Can I ask exactly what you’re trying to achieve? If you’re trying to make the pet walk on the ground, I would suggest using other methods anyway. But I also see you adding the x and z axis from the raycast for some reason. Then the Y axis should be the raycast Y position plus half of the pet’s size. You should also probably be getting the raycast origin from an offset of the player’s character rather than the pet itself, that is, unless you’ve already got a following system you want to keep. Then just take the X and Z axis from that, and then the Y axis of the player character’s rootpart or something.
i want like that the pet can detect the ground, and not on the ground position with the player, thats why im trying to use the Raycast for the Y Position. The X and Z Position are already working with no problem or anything
I meant for the starting Y position, that way it doesn’t start floating upward. Although it shouldn’t really be doing that to begin with. However, another reason I’d recommend using the Y position from the player is so that the pet can’t get stuck in the floor.
Take the Y axis of the root part and the current X and Z axis of the pet for the origin Vector3. Then shoot a ray downward from that point. Then you can set the pet’s position to the raycast’s result position and offset it upward by half of the pet’s Y axis size.
If I understand you correctly, you already have the basic concept done right. You just put the ray direction to Vector3.new(0,-500,0) or something. I’m just saying to use the player’s Y axis for the origin. Then use the raycast hit position and the new position, plus half of the pet’s Y axis size for the to the Y axis position offset.
local Raycast = workspace:Raycast(Player.Character.PrimaryPart.Position + Vector3.new(0,20,0),Vector3.new(0,-250 + Player.Character.PrimaryPart.Position.Y,0),blacklist)
if Raycast then
BP.Position = (Player.Character.PrimaryPart.Position + Pos) - Vector3.new(0,Raycast.Position.Y + script.Parent.PrimaryPart.Size.Y/2 - 3,0)
print(Raycast.Position.Y)
end
But its still always the same Y Position, and going trough parts (and it shouldnt go trough parts, it should go on the top of the part (what raycasting should do, but it isnt)), and i blacklisted the pet