I am making a pet system for my game and when the player opens a capsule, the pet gets cloned and is put in a viewport frame so the player can see what they get. The only problem is that it’s not facing forward. I’ve tried setting it to a certain rotation, and it works for most of the pets but some of them don’t face the same direction as the others. Is there a way to fix this? Thanks!
A quick solution that I would come up with is to have some extra main part that is aligned with the forward direction of the pet, this could be a 1x1x1 part, a bounding box, or whatever. You use that part to base the rotation, this would get rid of inconsistencies. I think a bounding box would work the best.
If you haven’t, check that the FrontSurfaces of the primary part of all pet models are oriented in the same way (Part->Properties->Surfaces->FrontSurface). If the front face of this part is oriented differently for each pet, it may make finding a solution to your problem more difficult.
Do you re-orient them in any way after you clone them, or do you just move the position of the clone and keep the orientation of the original? Seems like if it works most of the time, the place to look for problems would be on the models that aren’t working right (assuming it’s the same models that are consistently coming in the wrong way).
If you want to share it, what does the bit of code you’re using look like that clones/orients the model and attaches to the VP?
Yeah… The only way I can get it to show incorrectly is if the model itself is rotated differently than other pets. There’s technically no need to “fix” the rotation of a model’s primary part. Just turn all the models so they point the same way in the world and set their positions the same, then place the camera where you want it relative to them (as Quenty suggests). I would probably orient the primary parts of pets all the same way if it were my game because that kind of thing triggers my OCD, and I’d be afraid that an inconsistency there would come back to bite me in another part of the code, but for this it doesn’t matter.
local pet = game:GetService("ReplicatedStorage").PetsFolder:FindFirstChild(pic):Clone()
pet.Parent = Reveal
local cam = Instance.new("Camera")
Reveal.CurrentCamera = cam
cam.FieldOfView = 15
cam.Parent = Reveal
cam.CFrame = CFrame.new(Vector3.new(0, 5, 20), pet.Position)
Maybe something like that with all your pet models at origin and facing the same direction (Z in the case of snippet above).
I have tried all of the above with moving the camera and the pets having the same orientation, but for some reason some are still different than others…
first have your pet and a small cube (1x1x1) size is usually perfect
ignore the guy in the back please
set the cubes front surface to hinge
this is so we can see the front direction easily
position the cube inside the pet
and align the pets face with the hinge direction
now just group those together and set the primary part to the cube
after you have done that place the pet in ReplicatedStorage
create a local script
local Player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Distance = 4 -- how far the camera is away from the pet
function ShowPet(Name)
local Pet = ReplicatedStorage:FindFirstChild(Name) -- searches for the pet
if Pet then -- checks if the pet exists
Pet = Pet:Clone() -- clones the pet
local ScreenGui = Instance.new("ScreenGui")
local ViewPort = Instance.new("ViewportFrame")
local Camera = Instance.new("Camera")
-- creates a new screengui, viewport, and camera
ViewPort.Size = UDim2.new(0, 250, 0, 250)
ViewPort.Parent = ScreenGui
-- sets the size and parent of the new viewport
Camera.Parent = ViewPort
Pet.Parent = ViewPort
-- more parenting
ViewPort.CurrentCamera = Camera -- sets the viewports camera to our new camera
ScreenGui.Parent = Player.PlayerGui -- parents the gui we created to the players playergui
Camera.CFrame = CFrame.new(Pet.PrimaryPart.Position + Pet.PrimaryPart.CFrame.LookVector * Distance, Pet.PrimaryPart.Position) -- sets the camera cframe to be at the pets primary parts position and then we offset it by pets primarypart lookvector * our distance variable
end
end
you would obviously want to edit the script to suite your needs e.g changing the size and position of the viewport or maybe adding some detail to it
let me know if you have any questions or need help