generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Trying to make third person camera

Previous Thread :: Next Thread 
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
02 Aug 2016 09:54 PM
RenderStepped:connect(function()
Camera.CFrame = Character.Head.CFrame * CFrame.new(2, 1, 5)
end)

That's all I got so far, attaching the camera to the shoulder. How can I turn it into a third person camera like in Strobe?

https://www.roblox.com/games/287335491/Strobe-II

The key difference is that the A and D keys don't turn your character, they just move your character.
Report Abuse
Wowgnomes is not online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
02 Aug 2016 10:07 PM
disconnect humanoid controller and create your own
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
02 Aug 2016 10:19 PM
I think what you're looking for is:
Humanoid.AutoRotate = false

However, you need to create a sensitivity controller for screen movement


Lead Developer of Theatric Entertainment
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
02 Aug 2016 10:21 PM
I tried doing that earlier but one problem I ran into is that I don't know how to lock the mouse to the center of the screen
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
02 Aug 2016 10:22 PM
Use the userinput service to detect when the mouse moves, and apply rotation to the camera based on the direction the mouse is moving

and also lock the mouse

Also its camera.CoordinateFrame not CFrame unless they made an alias property
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
02 Aug 2016 10:22 PM
game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter

This will lock your mouse to the center of the screen


Lead Developer of Theatric Entertainment
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
02 Aug 2016 10:29 PM
@Roy

I don't see anything on UIS wiki for an event for mouse movement.

@c0m

Thanks didn't notice that before. But if I right click, it unlocks the mouse from the center?
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
02 Aug 2016 10:30 PM
With the locked mouse, how would I get the direction the mouse is moving?
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
02 Aug 2016 10:31 PM
Try putting the MouseLock line inside your RenderStepped loop.

Also, mouse movement can be found through UIS.InputChanged

UIS.InputChanged:connect(function(InputObject,GameProcessedEvent)
if InputObject.UserInputType == Enum.UserInputType.MouseMovement then
--From here, you get the DeltaX and the DeltaY, I can't seem to remember off the top of my head how it goes though
end
end)


Lead Developer of Theatric Entertainment
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
02 Aug 2016 10:38 PM
Even with the locked mouse, the UIS can detect what direction the mouse is moving in using that DeltaX and DeltaY I was talking about.


Lead Developer of Theatric Entertainment
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
02 Aug 2016 10:47 PM
I was able to make a basic camera. The sensitivity is a bit high by default though. Any more advice for something I should add is welcome :-) Also, should I use RenderStepped or BindtoRenderStepped?

Character.Humanoid.AutoRotate = false

RunService.RenderStepped:connect(function()
Camera.CFrame = Character.Head.CFrame * CFrame.new(1.5, 1, 7)
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
end)

UIS.InputChanged:connect(function(InputObject,GameProcessedEvent)
if not GameProcessedEvent then
if InputObject.UserInputType == Enum.UserInputType.MouseMovement then
print(InputObject.Delta.x)
Character.Torso.CFrame = Character.Torso.CFrame * CFrame.Angles(0, math.rad(-InputObject.Delta.x), 0)
Character.Torso.Neck.C0 = Character.Torso.Neck.C0 * CFrame.Angles(math.rad(InputObject.Delta.y), 0, 0)
end
end
end)
Report Abuse
devCrucible is not online. devCrucible
Joined: 17 Jul 2016
Total Posts: 40
02 Aug 2016 11:24 PM
Use RenderStepped. I personally think it's more efficient for refreshing.
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
03 Aug 2016 09:27 AM
I tried to add on a limit to how high on the y axis you can look up or down, but the system doesn't work that well because sometimes you can glitch it. What's the problem with it?

RunService.RenderStepped:connect(function()
Camera.CFrame = Character.Head.CFrame * CFrame.new(1.5, 1, 7) -- Lock to side
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
end)

local y = 0
local function SetY()
Character.Torso.Neck.C0 = CFrame.new(0, 1, 0) * CFrame.Angles(math.rad(y), 0, 0)
end

UIS.InputChanged:connect(function(InputObject,GameProcessedEvent)
Character.Torso.CFrame = Character.Torso.CFrame * CFrame.Angles(0, math.rad(-InputObject.Delta.x), 0)
if InputObject.Delta.y >= 0 then
if y < 70 then
y = y + InputObject.Delta.y
SetY()
end
elseif InputObject.Delta.y < 0 then
if y > -70 then
y = y + InputObject.Delta.y
SetY()
end
end
end)

Also, is there a way I can set the camera to a part of the character that doesn't move? If I were to do a very dynamic walk animation, and the head moves, then the camera moves along with it. I just want it to be centered on a static point independant of animations that twist and turn the character.
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
03 Aug 2016 10:01 AM
Okay, sorry for the slow response:

Try connecting it to the HumanoidRootPart for less movement.

Next as to your sensitivity, you account for the current Y but you don't account for the added Y. What you need to do (I've done this before btw) is:

if y + NEW_VALUE < MAX_VALUE then
y = y + InputObject.Delta.Y
end

Also, your SetY() function is unnecessary, you can just add that line at the end of your function, this probably wouldn't create a noticeable change in any sort of lag (I doubt there is any), but it would decrease lag by a tiny amount, and it always helps to have optimized code. So at the end, right before you end the InputChanged function, just add that line, and then remove the connections inside the code, this will also make your code shorter.


Lead Developer of Theatric Entertainment
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
03 Aug 2016 10:01 AM
Fixed some stuff, made some more problems.
https://www.roblox.com/games/19757864/Testing

Here's the script. I had to change the Neck.C1 because the head was backwards. Overall, I think I made the math overly complex. I also changed the camera base in the renderstepped to the HumanoidRootPart because it doesn't move.

local y = 0

RunService.RenderStepped:connect(function()
print(y)
Camera.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(1.5, 2.5, 6) * Character.Torso.Neck.C0 * CFrame.Angles(math.rad(-90), 0,0 )
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
end)

Character.Torso.Neck.C1 = Character.Torso.Neck.C1 * CFrame.Angles(0, math.rad(180),0)
local function SetY()
Character.Torso.Neck.C0 = CFrame.new(0, 1, 0) * CFrame.Angles(math.rad(y + 90), 0, 0)
end

UIS.InputChanged:connect(function(InputObject,GameProcessedEvent)
Character.Torso.CFrame = Character.Torso.CFrame * CFrame.Angles(0, math.rad(-InputObject.Delta.x), 0)
if InputObject.Delta.y >= 0 then
if y < 70 then
y = y + InputObject.Delta.y
if y > 70 then
y = 70
end
SetY()
end
elseif InputObject.Delta.y < 0 then
if y > -70 then
y = y + InputObject.Delta.y
if y < -70 then
y = -70
end
SetY()
end
end
end)


SetY()
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
03 Aug 2016 10:14 AM
I just tested your game and I just want to inform you that your Y is inverted, I don't know if that was intentional.

I would also suggest lowering the maximum and minimum angle to 60 so you aren't going past your character with the camera.

Next, I would like to address your custom character meshes in there (I don't know if you're going to use those particular ones), since those appear to be one part meshes, you can't animate their arms or anything, just wanted to let you know that, if they are multiple parts then they can be animated.

As for your code, divide the InputObject.Delta.Y and InputObject.Delta.X by 3 or so to create a lower sensitivity while keeping with the player's mouse movements.

If you would like to see how I used sensitivity in my weapon systems, you can view the place here:
https://www.roblox.com/games/464817132/Poluchit-Rekt-Mat

I'm currently testing attachments, bullet drop, bullet speed, vaulting, the death camera (usually first person, but I was testing how third person looks), and animations, if an animation puts your gun in an abnormal position, simply re-equip the weapon, it fixes any weird problem you're having 9/10 times. If all else fails, reset and try again with a new weapon.


Lead Developer of Theatric Entertainment
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
03 Aug 2016 10:17 AM
I want the camera to be locked more so on the Head position entirely, but right now it's more or less rotating around the camera point behind the camera. How can I change that?
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
03 Aug 2016 10:20 AM
Using just math, how can I center the camera tilt around the heads position? Right now its on HumanoidRootPart, and I moved the CFrame up some, but it doesn't seem to be working right.
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
03 Aug 2016 10:21 AM
Is this published so I can test? I'm slightly confused as to what you mean. I believe what you're saying is that the camera is rotating more around the center of the character, and you want it rotated around the head, the fix to this problem would be to raise the camera between the offset between the HumanoidRootPart and the Head, which by default is a 1 stud difference.


Lead Developer of Theatric Entertainment
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
03 Aug 2016 10:28 AM
Finding the exact distance between the center of the HumanoidRootPart and the Head can be found using magnitude, however this accounts for the X,Y,Z and I believe you only want the Y offset.


Lead Developer of Theatric Entertainment
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
03 Aug 2016 10:32 AM
I've centered the camera on the point the Head is at. I've made the Testing place first person now, so you can see that the Head and camera aren't aligning when you move. The "y" variable always determines the rotation of the Neck C0 & Camera rotation. The "y" variable is working fine with my UIS system, so I'll exclude it here. The only thing messing up is the math.

local y = 0
Character.Torso.Neck.C1 = Character.Torso.Neck.C1 * CFrame.Angles(0, math.rad(180),0)

RunService.RenderStepped:connect(function()
Camera.CFrame = Character.HumanoidRootPart.CFrame * CFrame.new(0, 1, 0) * Character.Torso.Neck.C0 * CFrame.Angles(math.rad(-90), 0,0 )
end)

local function SetY()
Character.Torso.Neck.C0 = CFrame.new(0, 1, 0) * CFrame.Angles(math.rad(y + 90), 0, 0)
end
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
03 Aug 2016 10:34 AM
Can I see the Testing place?


Lead Developer of Theatric Entertainment
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
03 Aug 2016 10:34 AM
https://www.roblox.com/games/19757864/Testing
Report Abuse
C0mmando323 is not online. C0mmando323
Joined: 15 Dec 2012
Total Posts: 394
03 Aug 2016 10:38 AM
Oh, I understand now! This is simply an order issue. The fix to this problem is to set the rotation before moving the camera on it's offset. Just move your rotation line before your position line.


Lead Developer of Theatric Entertainment
Report Abuse
AntiFiter is not online. AntiFiter
Joined: 14 May 2009
Total Posts: 12290
03 Aug 2016 10:42 AM
Can you change the script I posted? I don't understand what you mean. Remember, the SetY() is only called when you move your mouse, so it's independent of renderstepped.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image