Pet Follow System doesn't work if Pets aren't oriented properly

I have a pet system that uses body moves (body position & body gyro) to have the pet float above and behind the player. The problem is that some Pets will face backwards as opposed to the correct way. This is because the orientation of the Pets was not made the same way (made in blender)

bodyPosition.Position = Vector3.new(2, 2, 3) + humanoidRootPart.Position
bodyGyro.CFrame = humanoidRootPartCache.CFrame * CFrame.fromEulerAnglesXYZ(math.rad(0), math.rad(90), math.rad(0))			

I need a way to set the orientation to either -90 or 90 based off the pets’ current orientation.

Just to demonstate:

Pet with orientation (0, 0, 0)
firstpet

Pet with orientation (0, 180, 0)
fgnfgnfgnfgn

What I do to combat this is I set the CFrame to its own Position with a lookAt direction that points forwards from the humanoidRootPart. Try this and let me know if it works

bodyGyro.CFrame = CFrame.lookAt(petHeadPosition, petHeadPosition + humanoidRootPart.CFrame.LookVector)

You do need to get the petHeadCFrame and petHeadPosition but that should not be too hard

I’ll give it a try, thank you!

One issue, isn’t CFrame.lookAt(vector3, vector3) not a CFrame?

CFrame.lookAt(pos, lookAt) returns a cframe with the position of pos and a rotation that makes it point towards lookAt. Not sure what the exact equivalent is but it does return a CFrame

Right, but passing in petHeadCFrame as an argument is invalid right, since it’s a CFrame not a Vector3 which is what pos and lookAt take?

ohhh yeah that is my mistake. Just make it petHeadPosition. Good catch!

1 Like

Yeah, that’s what I thought, I just wasn’t 100% sure if I was correct or not.

Now, it’s doing this
gsdgsdgsdgsd

Updated code is:

bodyGyro.CFrame = CFrame.lookAt(petClone.PrimaryPart.Position, petClone.PrimaryPart.Position + humanoidRootPart.CFrame.LookVector)

That means the body has a wrong front orientation in comparison with the ears and face. Can you confirm the face decal is set to the front face of the pet head? Also you can just rotate the pet head 90 degrees so it matches and then re-weld it if you have it welded.

Just to be clear this is how the Pet is structured, the Ears and Body are the same MeshPart. Also, turning it 90 degrees would work for this Pet, but since some others are opposite orientation, it would mean the pet would face backwards. The primary part of the Pig model is the Pig MeshPart.

sdvsdvsdvsd

Hmm to fix pets that have it backwards you could add an invisible part that is the primarypart and make sure that has the right orientation. Then just weld it to the pet model. That way it shouldn’t visually change but should still work just fine for all pets without much work

1 Like

I’ll try doing that, I think next time I need Pets I’ll get a Pet modeler who makes all the pet the same orientation lol

Thank you, it works perfect now! :grinning_face_with_smiling_eyes: