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.
#Camera Return
1 messages · Page 1 of 1 (latest)
** You are now Level 8! **
I've tried things such as adding and subtracting the difference in rotations, tweening to certain locations, etc. etc. and it has not worked.
Sine and cosine
Could you elaborate please?
Like for example imagine this:
The camera is on a part of a sphere, the goal is to move the camera from the current part of the sphere to a desired part, whilst moving along the surface. Now imagine that sphere is placed around the player's character
Or a more practical example, in games like GoW Ragnarok when you let go of the camera stick it returns in an orbit fashion
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
Hold on ill find an example
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)
Heres a manual example I did with my camera system. When the camera moves back to where it was that is simulating the return script.
Oh
Hopefully that makes more sense lol
Js tween it's orientation
To CFrame.Angles(0,0,0)
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
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
Will do
For sphere should I just create like an actual part?
I did this but it had an error:
local sphere = Instance.new("Part")
sphere.Shape = Enum.PartType.Ball
sphere.Size = Vector3.new(5,5,5)
sphere.Parent = workspace
sphere.CFrame = char.PrimaryPart.CFrame
sphere.Transparency = 0.5
sphere.Anchored = true
sphere.CanCollide = false
Whats the error
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)
do center.Position
you can just change the first line to this
local center = sphere.Position
Should work best
** You are now Level 3! **
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
Ur supposed to run the function only after u let go of ur mouse
Tru that
I did
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
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
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.
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?
Yes exactly
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 ^_^
Thank you
This can come in handy for sure so its good pratice for me
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
try shift-lock to see if it does something weird like it does for me lol
Yeah I dont think it works I might have to go back to the drawing board
wait another question.. when you say orbit around the character.. you mean like have the camera move in circles in the radius of a sphere moving at different angles every time?
This is the current script for the camera system:
uis.MouseBehavior = Enum.MouseBehavior.LockCenter -- Ensure mouse rotates around character (Because it cant move)
uis.MouseIconEnabled = false -- Ensure cursor is invisible
Its kind of hard to explain
alright, I'll see what I can do.
Thank you
This what I got so far.. Watcha think?
@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
Let me show an example real quick
I think im starting to understand what you aiming for
I will wait for this example to verify
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.
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
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
I think i'm finally understanding your idea
Awesome
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
Yeah thats the idea im going for
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
** You are now Level 4! **
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?
Actually I think im only one line away from solving it one second
awesome
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
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
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
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
lets gooooo!!!
yes keep me updated! I learned a few things myself from just helping you so its a win win!
Awesome!
@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 😭)
thats awesome!!!
I'm glad you got to it in the end! Hopefully I was of help here lol you pretty much solved it at the end ^_^
You helped out a ton man, if you weren’t there it might’ve taken another 5 hours to figure it out