So, I have been going crazy on trying to find the best way to make a pet follow a player WITH OBJECT DETECTION so that it doesn’t ram into things.
I have an animation which requires the pets to have a humanoid and thought that pathfinding service was a great idea. Guess what it wasn’t if I would move away from the spot I was at before it would go to that spot instead of coming to me. I tried using attachments but that disabled my ability to make the pets use their animations. I am also trying to find a way where if I can click on an object the pets would go to it using a click detector. (Just like pet sim x). I thought this would be easier using attachments but then using attachments such as align position and align orientation would disable my ability to use the animations. If anyone has any ideas to help me that would be appreciated!
You could combine MoveTo for close ups and pathfinding for far away. Something like this:
How about object detection and telling the thing to go to a part just like in pet sim x.
I’ve never played that game, so you’ll have to be more specific about what “object detection” means.
so if there is a tree coming infront of a pet it would ram into it object detection would make it go around the tree.
Thats what pathfinding is for. If any base part is occluding the way for a Humanoid Based Character it just makes its way to go through the other way. If your game has a fixed map then thats way better! You can use pathway modifiers to help ignore or force the pet to move.
2nd way is using MoveTo and RayCasting.
:MoveTo just moves it without detecting any obstacles.but we can change that about using Raycast.
So would I just use a while loop to just keep checking for raycasts???
How would this ray cast even work
Make a Folder for All the Obstacles or Tag them using Collection Service.
Now I want you to do another while loop in coroutine which just sets the CFrame of the pet to look at player and setting the X orientation to be Ground Level so our pet doesn’t look downwards.this will be useful later for raycast as we will use the look vector of pet.
You could do this using run service but we want to stop when we reach the position so we can use while loop here. We fire a raycast each fraction of second ( 1/60 of a second is Ideal in this case but if you want you can go higher or lower to your desire). For the raycast we create a new RaycastParam to Block other players characters and Other Pets or any object which shouldn’t be detected when the raycast is successful. Next we put that ray cast the we start the actual raycast with taking the Pets LookVector * 1 as Origin and then taking direction as as Pets LookVector * 10000. If raycast was successful we check if the path for player is good or not. If yes then Check if the player is too far away or the distance is Ok. If the distance is too far then teleport the pet. Near the player.next we check for obstacles. If the Raycast.Instance is Tagged or Is Parent of your Obstacle folder(do either) then we check for the nearest part and do move to there but we again check for obstacles and if there is a obstacle then we teleport it there.
Also if the players magnitude is less then 2.5 then do break in the Loop.
Hello. Sorry for bumping this topic but I still haven’t found a solution. My goal is to make a pet follow a player. I don’t know how I should do this anymore.