#Camera Return

1 messages · Page 1 of 1 (latest)

supple gazelle
#

So im trying to make a camera return system for my camera system. The idea is that when the function is run, the camera returns to the original position (CFrame.Angles(0,0,0)) and it does this smoothly. The tricky part is that I want to do this in a circular motion (As though its returning by pathing around a sphere which is around the player). This is a common feature in most games, where the camera returns back to a default position.

torn whaleBOT
#

studio** You are now Level 8! **studio

supple gazelle
#

I've tried things such as adding and subtracting the difference in rotations, tweening to certain locations, etc. etc. and it has not worked.

supple gazelle
frozen monolith
#

So I want to do this around a sphere part right?

#

U*

supple gazelle
#

Or a more practical example, in games like GoW Ragnarok when you let go of the camera stick it returns in an orbit fashion

frozen monolith
#

ill give u a small example of how to do orbital camera effects since idk what u mean

#

give me a sec to write code

supple gazelle
#

Hold on ill find an example

frozen monolith
#
local radius = sphere.Size.X / 2
local angle = 0
local speed = 5

RunService.PreRender:Connect(function(delta)
    angle += speed * delta
    local offset = Vector3.new(math.cos(angle) * radius, 0, math.sin(angle) * radius)
    Cam.CFrame = CFrame.new(offset)
end)
supple gazelle
frozen monolith
#

Oh

supple gazelle
#

Hopefully that makes more sense lol

frozen monolith
#

To CFrame.Angles(0,0,0)

supple gazelle
#

The problem with that is,

#

It goes in a line straight to the orignial point

#

Whereas I want it to return like it did in the video in a orbit like fashion

#

Any ideas? @frozen monolith

frozen monolith
#
local center = sphere --ur path
local radius = sphere.Size.X / 2
local height = 0
local angle = math.pi
local targetAngle = 0
local speed = 1.5

local connection
connection = RunService.PreRender:Connect(function(dt)
    angle = math.max(angle - dt * speed, targetAngle)
    local x = math.cos(angle) * radius
    local z = math.sin(angle) * radius
    local camPos = center + Vector3.new(x, height, z)
    Camera.CFrame = CFrame.new(camPos, center)
    if angle <= targetAngle then
        connection:Disconnect()
    end
end)
#

Try that @supple gazelle

supple gazelle
#

Will do

supple gazelle
frozen monolith
#

Whats the error

supple gazelle
#

Workspace.DNT1B.Camera System.Default Camera:54: attempt to perform arithmetic (add) on Instance and Vector3

#

For this line:
local camPos = center + Vector3.new(x, height, z)

frozen monolith
#

do center.Position

manic wraith
#

you can just change the first line to this

local center = sphere.Position

Should work best

torn whaleBOT
#

studio** You are now Level 3! **studio

supple gazelle
# frozen monolith do center.Position

Okay so basically what it does is now it starts the camera on the 180 degrees away from where it starts, then rotates back to where it was when the function started. Also I think we might be going about this wrong, I think we should try to do a rotation script rather than moving the camera along a part.

#

This way its more versatile

frozen monolith
#

Tru that

supple gazelle
#

Hold up let me get a video of what happens

#

But I think we should be trying to rotate the camera angles to match CFrame.Angles(0,0,0) so that its more versatile

frozen monolith
#

Ye idk

#

Maybe try doing it w only sin or who ly coa

#

Or w only cos

#

or lerp

manic wraith
# supple gazelle

is the whole purpose of this is to rotate the camera based on the position of the part? why not make it rotate around the player instead of a part?
also, I think CFrame would be best for this method.

#

this is what I came up with by setting it to the player instead of a part. is this what you aiming for @supple gazelle

supple gazelle
#

The original idea is to make a camera return script which makes the camera return to the default behind the head position. Currently my custom camera system is an orbital design, and the idea is that under certain circumstances (Such as when you start moving) the camera rotates back around to behind the player, like it does in games such as God of War ragnarok, or others.

manic wraith
#

so like an idle camera rotate? like when you don't move for a certain amount of time it will start the orbital camera rotation and when player moves it will in term deactivate afk and return the camera back to normal or how you said behind players head?

manic wraith
#

I see! That is actually very creative idea. I used to play games that does something similar.. Hmm, let me do some testing real quick and see what I come up with. I will keep you posted and guide you to your answer ^_^

supple gazelle
#

Thank you

manic wraith
#

This can come in handy for sure so its good pratice for me

supple gazelle
#

Ill keep working at it too

#

I think im getting close,

#
local goalAngles = CFrame.Angles(0,0,0)
    local currentAngles = camera.CFrame:ToEulerAnglesYXZ()
    ts:Create(camera, TweenInfo.new(1), {CFrame = CFrame.new(camera.CFrame.Position) * goalAngles}):Play()

Is what I have now, and it works completely except it has a slight error that it rotates the camera on the spot rather than in an orbit around the character

manic wraith
supple gazelle
#

Yeah I dont think it works I might have to go back to the drawing board

manic wraith
supple gazelle
manic wraith
#

alright, I'll see what I can do.

supple gazelle
#

Thank you

manic wraith
supple gazelle
#

I think maybe theres a little misunderstanding:
The idea is that after a certain amount of time or when the character starts moving again, the camera shifts from where it currently is to behind the player for a more suitable position to continue. For example, my camera is viewing the right side of my character, but then I start walking so my camera orbits back around to the back of my character

manic wraith
#

so you are in a third person view?

#

ohhh wait

supple gazelle
#

Let me show an example real quick

manic wraith
#

I think im starting to understand what you aiming for

#

I will wait for this example to verify

supple gazelle
#

So in this video I kind of did it manually but as you can see im using my camera as normal but when I start walking it shifts back to the back of my character so its more effective for walking.

manic wraith
#

So from my understanding you want the camera to either snap or orbit slowly to the back of the player based on where the current players character is facing so they don't have to manually move the camera themselves and they can get back into action? is this right? Im sorry if I am not getting it ^_^

#

I also don't mind helping out even if it takes us a while to udnerstand your goal since this is also helping me grow as a scripter so you take your time as well

supple gazelle
#

The idea is that it orbits to the back of the player once you begin moving or after a certain amount of time has passed. So for example, you're looking at your character from the front, but then you start moving so your camera orbits around to the back

manic wraith
#

I think i'm finally understanding your idea

supple gazelle
#

Awesome

manic wraith
#

hmm this is tricky but my work around is to just orbit the camera to the back of the player when they are idle

#

here is an example

#

whatcha think? @supple gazelle

supple gazelle
#

Yeah thats the idea im going for

manic wraith
#

awesome!

#

the idea of the camera moving to the back of the character is kinda wonky since on my test as you move and this shifts the camera it will just make you move towards the camera as it orbits making you go left or right based on the camera fixing itself

torn whaleBOT
#

studio** You are now Level 4! **studio

manic wraith
#

only way around it was just to move it when they are idle

#

at least thats my way around it

#

want me to send you script on DM so you can review how I made it possible?

supple gazelle
#

Actually I think im only one line away from solving it one second

manic wraith
#

awesome

supple gazelle
#

In this line:

local goalCFrame = (CFrame.new(char.PrimaryPart.Position) * goalAngles) * CFrame.new(Vector3.new(0,6,12))

The last bit where it multiplies by the CFrame and Vector is supposed to put the position behind the Primary Part but relative to it

#

So bascially placing CFrame behind a part

manic wraith
#

yeah, for sure

#

the way I did it is based on the characters rootpart

supple gazelle
#

The only issue I have left to solve is making it so that the goalCFrame is set at a certain vector behind the primary part and that it is relative to the primary part so that if the character rotates it stays behind

manic wraith
#

try doing char.PrimaryPart.CFrame * CFrame.new(0, 6, 12)
see if that does something

#

let me know if you got it. I'll be around to help

supple gazelle
#

I got it!!:

local goalAngles = CFrame.Angles(0,0,0)
    local currentAngles = camera.CFrame:ToEulerAnglesYXZ()
    local goalCFrame = (char:GetPivot() * CFrame.new(0,1.55,12.5)) * goalAngles
    ts:Create(camera, TweenInfo.new(1), {CFrame = goalCFrame}):Play()

If you want i can keep you updated on how it looks after I polish it all

manic wraith
#

lets gooooo!!!
yes keep me updated! I learned a few things myself from just helping you so its a win win!

supple gazelle
#

Awesome!

supple gazelle
#

@manic wraith Here's the polished product! It smoothly rotates the camera back after 10 seconds of inactivity! (I put it to 5 seconds to demonstrate)

#

(this took me 10 hours of nonstop scripting 😭)

manic wraith
supple gazelle