I’m having trouble making my pet look at my character right now and I can’t seem to figure it out. I’ve tried using startPosition and targetPosition but it doesn’t seem to do anything with my pet. As you can probably tell in the picture. My pet constantly looks off to the side no matter what direction I face. If I try and look at the pet it turns to the side again and I’m not sure how to fix it. Does anyone have an idea?
local pet = script.Parent
function givePet(player)
if player then
local character = player.Character
local startPosition = Vector3.new(0,0,0)
local targetPosition = player.Character.Head.Position
print(player.Character.Head)
if character then
local humRootPart = character.HumanoidRootPart
local newPet = pet:Clone()
newPet.Parent = character
local bodyPos = Instance.new("BodyPosition", newPet)
bodyPos.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
local bodyGyro = Instance.new("BodyGyro", newPet)
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
while wait() do
pet.CFrame = CFrame.new(startPosition, targetPosition)
bodyPos.Position = humRootPart.Position + Vector3.new(-5,2.5,-3)
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
givePet(player)
end)
end)
Hey TooMuchRice!
So this one’s actually pretty simple thankfully enough! Since your pet has a BodyGyro
it will be forced to a certain orientation and you may not be able to edit that as simply as if you could without one.
In this case what we need to do is tell the BodyGyro
what orientation we want it to go to. This is perfectly demonstrated on the roblox dev wiki like this:
So in this case instead of:
pet.CFrame = CFrame.new(startPosition, targetPosition)
We actually want to do this:
bodyGyro.CFrame = CFrame.new(startPosition, targetPosition)
I hope this helps!
Ok first of all, why are you cloning the “pet”, and instead of calling to the clone, you call to the original?
Secondly, maybe try instead of changing the CFrame of the pet, you change the CFrame of the bodygyro
Thirdly, I’m not sure your start position is Vector3.new(0,0,0) as you state?
function givePet(player)
if player then
local character = player.Character
print(player.Character.Head)
if character then
local humRootPart = character.HumanoidRootPart
local newPet = pet:Clone()
newPet.Parent = character
local bodyPos = Instance.new("BodyPosition", newPet)
bodyPos.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
local bodyGyro = Instance.new("BodyGyro", newPet)
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
while wait() do
bodyGyro.CFrame = CFrame.new(newpet.Position, player.Character.Head.Position)
bodyPos.Position = humRootPart.Position + Vector3.new(-5,2.5,-3)
end
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
givePet(player)
end)
end)
edit: Repvalor explained
1 Like
I appreciate the help and I understand what you are saying but for some reason it just tilts the body of it.
I am not very experienced with BodyMovers but it looks like the Pet is now looking at your character, just that the rotation of your pet makes it so that the LookVector is at the side of the pet instead of the front of the pet. I would think that you have to rotate your CFrame 90 degrees in one axis.
Make sure your start position is actually your “start position” because, will it always start at the Vector (0,0,0)? I would just make the “start position” where the pet is currently located at.
But, it is exactly what AbandonedRick said.
Either your decal is not actually on the front of the part of the pet (the look vector side of the pet), or your CFrame is off.
So whichever is the problem, either fix the decal’s position on the block, or if the CFrame is off, then multiple it by 90 degrees (or however many degrees it needs to rotate).
For example:
bodyGyro.CFrame = CFrame.new(newpet.Position, player.Character.Head.Position) * CFrame.Angles(math.rad(DEGREES),0,0)
I’m not sure which direction you actually need to rotate it.
There is no real start position for the pets since they will be on the serverstorage waiting to be bought. Also the pet isn’t just a singular sphere so changing the decal won’t do anything. It is purely just an issue with the CFrame that I can’t seem to fix.
Can you check to make sure the LookVector of the “pet” is in fact facing the player?
In-game, check to see if the “front” of the part is facing the player. If it isn’t, then the fix is easy as it means the gyro is working, but the CFrame is incorrectly listed.
I actually just tried something else with some of your suggestions and got it to work. Thanks.