How to make pet position depends of size

Hello. I have hatching script that clones pet model and places it like Cam.CFrame*CFrame.new(0,0,z_offset)
This z_offset is equals to -pet.PrimaryPart.Size.Z*2. If you will hatch some huge pet, this pet gonna far away, but I wanna make it closer to cam. How to do this?

1 Like

Is the pet one part? You can try looking into GetExtentsSize. Otherwise, could you clarify a little more what you’re trying to do, or show an image?

No, its Model, inside this model placed MeshParts
If, by hatching, player gets some doggy, so pet will be on normal distance. But when player gets some huge doggy, pet must be shown, but not far away.

Like this:


You could adjust that same z_offset to move it closer to cam, right? If there’s a certain way you want it to look you can experiment with it, maybe multiply it by some variable number.

Yeah, I was thinking abt this. But I wanna make the script automatic to set position

The image you show seems like the big dog is too close to the camera, which seems to be the opposite of what you’re saying in the original post. Do you want the big dog to be seen relatively the same as the smaller dog? I notice the text is on the big dog while the text is not on the small dog.

I just imaged that incorrectly, sorry for this. In my system when player hatches some basic pet like dog, the position of pet sets good. But when some pet that is bigger than, like, some dog, so this pet gonna be moved a bit far. So, do you have any ideas to make pets, that bigger than standard pets closer?

It moves farther away because the Z size is just bigger. You’re moving it based on the size so naturally bigger moves farther away.

This z_offset just guarantees you move it enough as to not block the camera I would assume. Try the multiplier I mentioned as it can add an offset based on the size of the pet, moving it closer when the size is bigger but moving barely when the size is smaller.

Like adding some variables inside the pet or smth like this?

Add a variable named multiplier, set z_offset to z_offset * multiplier after you did the equals to -pet.PrimaryPart.Size.Z*2, then test ingame. Change the multiplier in testing and see how that goes. Lower multiplier moves closer and higher multiplier moves farther away.

I’ll let you know if I find a more rigorous way to do it.

No, I dont wanna make like that, I wanna make z_offset based on PrimaryPart.Size.X/Y/Z, nvm. Cuz it will be a bit dreary. I wanna change -pet.PrimaryPart.Size.Z*2 to smth like -pet.PrimaryPart.Size.Z*...

you get the magnitude of the extents of the model, divide it by 2. that’s your offset

like that:
local _,size = pet:GetBoundingBox() z_offset = -size.Z/2?

if the pet is a model then you get the pet:GetExtentsSize().Magnitude / 2 as the offset

nothing changed but thanks. Big pets still gets bit far than basic pets ¯_(ツ)_/¯

If I understood what you’re trying to do its something like this?

This will work assuming the pets primary part’s size is it’s actual size

local origin = workspace.Origin -- The part the pet should follow
local pet = workspace.Pet -- The model of the pet with a set PrimaryPart
local offset = 3 -- The offset from the origin part
local runservice = game:GetService("RunService")

runservice.Heartbeat:Connect(function()
	pet:PivotTo(origin.CFrame * CFrame.new((origin.Size.X / 2) + (pet.PrimaryPart.Size.X / 2) + offset, 0, 0))
end)

--[[
Origin width / 2 to offset the pets center to the right face of the origin
Pet's primary part width / 2 to make the pets left surface be next to the origins right surface
Add the offset
]]--

No, I wanna make big pets move closer to cam (when hatched the pet) and basic pets stay the same position from the cam

I reused the same math but replaced some things. Is this what you’re looking for?
It always stays 3 (or whatever you set it to) studs away from the camera no matter the size.

local origin = workspace.CurrentCamera
local pet = workspace.Pet
local runservice = game:GetService("RunService")
local offset = 3

runservice.Heartbeat:Connect(function()
	pet:PivotTo(origin.CFrame * CFrame.new(0, 0, -(pet.PrimaryPart.Size.Z / 2 + offset)))
end)

Unless you’re trying to make the big ones closer than the regular sized ones, in which case you’d have to make some sort of exponential system which I can’t help with

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.