ConnectedPets = game["Run Service"].Heartbeat:Connect(function()
for i, Pet in equippedPetsChar:GetChildren() do
if Pet.PrimaryPart and char and char.HumanoidRootPart then
local CharacterPosition = char.HumanoidRootPart.Position
local DesiredPosition = (char.HumanoidRootPart.CFrame*CFrame.new(0,0,4)).Position
local ActualPosition = workspace:Raycast(
DesiredPosition + Vector3.new(0, 20, 0),
Vector3.new(0, -50, 0),
raycastParams
)
if ActualPosition then
Pet.PrimaryPart.BodyPosition.Position = ActualPosition.Position + Vector3.new(0, math.max(Pet.Y.Value/1.9), 0)
else
Pet.PrimaryPart.BodyPosition.Position = DesiredPosition
end
Pet.PrimaryPart.BodyGyro.CFrame = CFrame.lookAt(Pet.PrimaryPart.Position, CharacterPosition)
end
end
task.wait()
end)
First we need to know if the problem is with the Raycast, add this
print(ActualPosition and ActualPosition.Position and ActualPosition.Position.Y)
to the code and see if the Raycast is alright.
also, what is the point of looping through all pets in a equippedPetsChar with this code? since the only input from the Pet itself is at the end, shouldnât the script be organized like this?:
ConnectedPets = game["Run Service"].Heartbeat:Connect(function()
if not char or not char.HumanoidRootPart then return end
local CharacterPosition = char.HumanoidRootPart.Position
local DesiredPosition = (char.HumanoidRootPart.CFrame*CFrame.new(0,0,4)).Position
local ActualPosition = workspace:Raycast(
DesiredPosition + Vector3.new(0, 20, 0),
Vector3.new(0, -50, 0),
raycastParams
)
for i, Pet in equippedPetsChar:GetChildren() do if not Pet.PrimaryPart then continue end
if ActualPosition then
Pet.PrimaryPart.BodyPosition.Position = ActualPosition.Position + Vector3.new(0, math.max(Pet.Y.Value/1.9), 0)
else
Pet.PrimaryPart.BodyPosition.Position = DesiredPosition
end
Pet.PrimaryPart.BodyGyro.CFrame = CFrame.lookAt(Pet.PrimaryPart.Position, CharacterPosition)
end
task.wait()
end)
this way you can do a single raycast for all of them, instead of re-doing multiple raycasts wiith same origin and direction within the same frame, which all result in the same value anyway.
i also, i donât get the point of having the task.wait() at the end, isnât this Heartbeat? why would it wait?
The wait and for loop in equippedpetschar were segments of code from when I originally had this in a while loop. I was going to change the X and Z positions for each pet in the folder, based on the number equipped and if theyâre flying pets, so the raycast wouldnât be the same for all of them, but I forgot about the wait, i was planning to clean up the code after fixing this bug. Hereâs the output for the print
How high/low is Y 1.3 relative to your ground?
also, Is the âcanQueryâ property of your ground enabled?
change up the âPrintâ to be
print(ActualPosition and ActualPosition.Position and ActualPosition.Position.Y,ActualPosition and ActualPosition.Instance)
so we can see which Object exactly is being hit by the Raycast. (no need to post a video tho, you can just check if itâs the ground that is being hit by it by clicking on itâs Name on the console, when printing an instance directly on console you can go to it with a click)
Also, CanQuery returns as true when I print it, it doesnât return as false even when the pet falls beneath the ground
canQuery is automatically enabled if canTouch is enabled, so unless you disable it, itâs a hidden property.
but from your last video⌠isnât it working? iâm not seeing anything fall through.
Itâs not working in the last video, I just didnât show replication of the bug in that 3 second clip. 2 seconds later it falls beneath the ground, here
.
is it also falling bellow ground on server view or is it a client-sided problem?
Hmm, do you reckon thatâs the issue? Sometimes the network ownership isnât entirely in the clientâs control, although thereâs not enough size for me to clip the whole video for you. Do you think itâs not a faulty raycast issue then?
also the pets are above the ground substantially in that clip because I enabled them to fly while debugging.
i mean, the raycast itself seems to be working pretty well based on the Y readings we saw before, iâve already moved away from the possibility of it being the problem to it being related to how the Movers work.
if you anchor the pet and set the petâs position directly instead of the target position for the mover, you should see (i hope so, lol) that the position is as it should be, which would prove the problem is with the physics surrounding the act of making it move using the BodyPosition, not the position being given.
if my test is right, maybe you should consider switching from BodyPosition (which is deprecated btw) to AlignPosition (which i think itâs kinda worse to work with, but works better in the end).
Yeah, I think youâre right, so I was doing align position to begin with and was thinking of transitioning back to it, but then how do I precisely set the pets at ground level with align position? I tried raycasting the pets with align position right at the ground, but it didnât work at all, that was why i switched to bodymovers.
The Raycast result is the desired ground level, the only thing you need to add is the Y offset which should be half of the Petâs Height.
unless i misunderstood your question, that should be it, it works very similarly to the BodyPosition youâre using, just with less bugs, specially replication ones.
(which is actually the same as an Humanoidâs HipHeight, the system Roblox uses to that Humanoids collide with the ground without actually colliding with it, too bad itâs an exclusive function of Humanoid).
Oh wait, yeah I think youâre right lmao, my brain is fried man
same for me, lol, imma go sleep now, good luck.
Was able to do it without switching to AlignPosition. Had to increase my max force to 6000.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.