Rotate a camera around a part in viewport frame like robinsons

Hello there

So I have an issue that 300 people have had in this platform and I’m getting tired of it.

What I want to do is pull a rotation of a camera like this bag right here

Yes, I know, odd game, well it was my childhood and I don’t forget how the things rotate.

Basically, I want to rotate a camera blocky-like not smooth-like. 0.3 seconds and the camera rotates 45 degrees, 0.3 seconds and the camera rotates 45 degrees. Nothing polished, but rudimentary.

The issue is that I don’t know how, and I’ve been looking EVERYWHERE for info and found nothing, bad code, good code, someone even used metatables, eww. Nothing of what I want FUUUUUU

1 Like

When rotating a camera around a object usually it is fixed to be looking and rotating a ta central point.

For this all you would need to do is move the camera around a single point at fixed distance.

We can use the bag as a central point for its rotation as this means we can use the look vector of a invisible part to achieve a smooth rotation at set distance. This requires a few steps on repeat:

  • Work out the amount per move and wait time
  • Rotate the part
  • Put camera at a distance from the parts look vector

why not just animate the backpack inside the viewportframe?

cosine and sine combined with radians are wonderful for doing this. Have you checked Polar Coordinate system out?

1 Like

I think you should rotate the object instead of the camera. This is what i do when i use viewportframes and i think its easier than rotating the camera.

From what I’ve seen

@xXxIAsdasIxXx, @http_shawn and @minimic2002

Rotating a part uses more resources than if you were to just rotate the camera.

Altough considering that what I need to rotate is just a mesh part, nothing of that block buildings, I could rotate the part and keep on with my life, but I want to rotate the camera instead of the part so it doesn’t get heavy låter on.

Maybe I should just do that, just rotate the part, but I’m thinking it can get ugly fast.

No, I haven’t, do you have any sources I can check?

When I use viewport frames like that I usually go for a simple up and down breathing and make it spin. I use animations as I see it as the easiest and doesn’t take up too much resources. You could rotate the camera, I just didn’t because I was too lazy.

1 Like

any method to rotate a part on itself? one that is blocky-like?

i can figure it out, but I’m asking because why not…

Try running this as a localscript, you can probably figure something out! (Don’t mind my bad code its just an example; you should be storing constants)

local tau = 2*math.pi
local t = 0
local cam = workspace.CurrentCamera
local radius = 5

local p = Instance.new("Part", workspace)
p.Anchored = true
p.Position = Vector3.new()

while true do
	t += tau / 100 --// 1/100 of a circle, i.e. 3.6 degrees.
	cam.CFrame = CFrame.lookAt(Vector3.new(math.sin(t)*radius, 0, math.cos(t)*radius), Vector3.new())
	wait()
end
4 Likes

Well, the part is rotating in the viewportframe, you know this much more than I do.

I have some issues

  • what do you mean by storing constants?
  • what should I to make the vision of the part be a bit from above instead of right at the same angle?
  • How do I set the camera f*rther away?

EDIT: I have something kind of figured out, I think I have something…

By storing constants, I mean I probably should not call the constructor multiple times constructing the same value. (Generally calculations etc.)
So instead of:

..., Vector3.new())

It should be:

local ZERO_VECTOR = Vector3.new()
...
..., ZERO_VECTOR)

To skew the angle a little, you can add another vector to the first argument (such as (0,-5,0) for looking from below).

To make it look a bit further away, you can adjust the radius variable.

I ended up mutilating it to this

local tau = 22.5*math.pi
local t = 0
local cam = script.Parent.CurrentCamera
local radius = 100

while viewport.Visible == true do
	t += tau / 100 --// 1/100 of a circle, i.e. 3.6 degrees.
	cam.CFrame = CFrame.lookAt(Vector3.new(math.sin(t)*radius, 0, math.cos(t)*radius), Vector3.new())
	wait(0.15)
end

Thanks for your help, I genuinely don’t know what sine cosine and tangent is, I approved that part in school but never understood it.

I will be seeing if there’s something else. I couldn’t change the position of the camera to be higher, but I guess it doesn’t matter, I just want to end this part for once.

Thank you…