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 » Game Design
Home Search
 

Re: camera rotation using gamepad

Previous Thread :: Next Thread 
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
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
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
06 Apr 2015 09:30 AM
bump
Report Abuse
gamehero is not online. 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
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
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 is not online. 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
xiaoxiao181 is not online. xiaoxiao181
Joined: 14 Aug 2008
Total Posts: 5882
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Game Design
   
 
   
  • 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