Making a model face forwards?

Hello, developers.

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!

3 Likes

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.

Does that mean I’d have to add a part to every single pet? There are a lot of them…

They are all on FrontSurface, idk why it’s doing this.

Ah yes, the orientation on all of them is different. I will try to make them all the same then tell you what happens.

[Edit: Oops. NM. Didn’t notice you replied again]

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?

Right so I changed the orientation to 0,0,0 and the same thing happens. Here’s the code to clone them and orient them:

local cam = Instance.new("Camera", Reveal)
local pet = game:GetService("ReplicatedStorage").PetsFolder:FindFirstChild(pic):Clone()
pet.Parent = Reveal
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = CFrame.new(cam.CFrame.p, pet.PrimaryPart.Position)
cam.CameraSubject = pet.PrimaryPart
cam.CameraType = Enum.CameraType.Fixed
cam.FieldOfView = 15
Reveal.CurrentCamera = cam
pet:SetPrimaryPartCFrame(CFrame.new(pet.PrimaryPart.Position) * CFrame.Angles(math.rad(75), math.rad(60), math.rad(-100)))

Issue: PrimaryParts orient in different directions.

We can fix this by just manually rotating things properly

  1. Don’t set PrimaryPartCFrame.
  2. Instead: move the Camera to the proper location
  3. Make sure all pets in ServerStorage are oriented in the same direction
  4. Update your clone script to clone properly

This way, no matter what way the PrimaryPart is oriented as “forwards” you can have pets oriented correctly too.

This is almost certainly the easiest configuration solution.

2 Likes

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 we have to setup the pet

first have your pet and a small cube (1x1x1) size is usually perfect

image

ignore the guy in the back please

set the cubes front surface to hinge
image
this is so we can see the front direction easily

position the cube inside the pet

image
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

image

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

image

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

9 Likes

Thank you so much!!

1 Like