|
| 05 Apr 2015 04:07 PM |
http://wiki.roblox.com/index.php?title=Gamepad_input
It's a good tutorial, sure, but it's fairly difficult to understand. I don't understand how it's actually rotating the camera, and on top of that it only rotates it horizontally.
Since I'm making a spaceship fighting game, the camera needs to be able to rotate around the ship freely using the right joystick. I'm sure you can understand just how frustrating this problem is.
Perhaps someone could help me out with this issue? I'm only concerned with the camera controls. I've been able to figure the rest of the gamepad out fairly easily. |
|
|
| Report Abuse |
|
|
| |
|
gamehero
|
  |
| Joined: 12 Jun 2007 |
| Total Posts: 1455 |
|
|
| 06 Apr 2015 10:09 AM |
I did a minor modification to the script you were talking about. It rotates on two angles instead of one now. I think this is what you meant you wanted...
local userInputService = game:GetService("UserInputService") local runService = game:GetService("RunService") -- Make variables for player, character, and camera local player = game.Players.LocalPlayer while not player.Character do wait() end local character = player.Character local camera = game.Workspace.CurrentCamera -- Update camera rotation every render frame local currentAngle = 0 local currentAngleY = 0 local deltaAngle = 0 local deltaAngleY = 0
runService.RenderStepped:connect(function() print(currentAngle,deltaAngle) currentAngle = currentAngle + deltaAngle currentAngleY = currentAngleY + deltaAngleY camera.CoordinateFrame = CFrame.new(character.Head.Position) * CFrame.Angles(0, math.rad(currentAngle), 0) * CFrame.Angles(math.rad(currentAngleY),0,0) * CFrame.new(0, 0, 10) end) -- Check for change event in input. Used for thumbstick input as those are analog userInputService.InputChanged:connect(function(input, processed) if input.UserInputType == Enum.UserInputType.Gamepad1 then -- Check left thumbstick and move character on change if input.KeyCode == Enum.KeyCode.Thumbstick1 then character.Humanoid:Move(Vector3.new(input.Position.X, 0, -input.Position.Y), true) end -- Check right thumbstick and change camera angle on change if input.KeyCode == Enum.KeyCode.Thumbstick2 then deltaAngle = input.Position.X * 5 deltaAngleY = input.Position.Y * 5 end end end) -- Check for user input ended events. Handles release of R1 and thumbsticks userInputService.InputEnded:connect(function(input, processed) if input.UserInputType == Enum.UserInputType.Gamepad1 then -- Stop moving character if left thumbstick released if input.KeyCode == Enum.KeyCode.Thumbstick1 then character.Humanoid:Move(Vector3.new(0,0,0)) end -- Stop moving camera if right thumbstick released if input.KeyCode == Enum.KeyCode.Thumbstick2 then deltaAngle = 0 end -- Make character move at normal speed if R1 is released if input.KeyCode == Enum.KeyCode.ButtonR1 then character.Humanoid.WalkSpeed = 16 end end end) -- Check for user input began events. Handles jumping and increasing speed userInputService.InputBegan:connect(function(input, processed) if input.UserInputType == Enum.UserInputType.Gamepad1 then -- If A button is pressed then make the character jump if input.KeyCode == Enum.KeyCode.ButtonA then character.Humanoid.Jump = true end -- If R1 is pressed then make the character move faster if input.KeyCode == Enum.KeyCode.ButtonR1 then character.Humanoid.WalkSpeed = 30 end end end) |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2015 12:11 PM |
I had to fix a few things, such as the resetting the the delta Y, but with this I should be able to compare it with the tutorial page and find out why each part does what it does. With this help, I should be able to integrate camera control into the flight controls. I really appreciate your help. |
|
|
| Report Abuse |
|
|
gamehero
|
  |
| Joined: 12 Jun 2007 |
| Total Posts: 1455 |
|
|
| 06 Apr 2015 12:30 PM |
The main idea is this part...
CFrame.Angles(0, math.rad(currentAngle), 0) * CFrame.Angles(math.rad(currentAngleY),0,0)
It doesn't work the same if you do it like this...
CFrame.Angles(math.rad(currentAngleY), math.rad(currentAngle), 0) |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2015 12:48 PM |
lol well that was easy to figure out thanks to you. I realized that all the delta angles were referring to was the angle the camera was pointing. I was so stupid trying to figure things out that I was thinking way too hard about it.
I've already got a fantastic prototype working.
Using a part I've named TestPart, I've created a base control script to fly it. The test craft rolls and changes pitch while flying. The camera moves around X and Y axes now, as well is rolling left and right on the Z axis now, in addition to being able to zoom in and out.
With some fine tuning I should be able to create a suitable prototyp for my Astro Storm game finally lol |
|
|
| Report Abuse |
|
|