You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want my character to be able to face up and face down when their cameras are looking up and down when flying. -
What is the issue? Include screenshots / videos if possible!
My character is just staying “flat”
https://gyazo.com/cc3dd98ff448fe9da6a45ba4d617daf9 -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I thought about using body gyros because I know it has something to do with rotation, but sadly I don’t know enough of how to do that. And the dev forums don’t really help me much either. I tried finding stuff about body gyros on YouTube, but they were very vague and didn’t address my problem.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
This is essentially what I want. This is from Ignite Games’ “Age of Heroes” on Roblox
This is what I want to achieve:
https://gyazo.com/569cde2556560e661dff3b6fa0417e41
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local camera = workspace.CurrentCamera
local UIS = game:GetService('UserInputService')
local idleAnim = char:WaitForChild('Humanoid'):LoadAnimation(script:WaitForChild('FlyingIdle'))
local flyingAnim = char:WaitForChild('Humanoid'):LoadAnimation(script:WaitForChild('FlyingMove'))
---[booleans]---
local isFlying = false
---movement keys---
local wPressed = false
local aPressed = false
local dPressed = false
local sPressed = false
--[Mouse stuff]--
local mouse = player:GetMouse()
UIS.InputBegan:connect(function(key,blah)
if blah then return end
---[Press F to fly]---
if key.KeyCode == Enum.KeyCode.F then
if isFlying then --[If character is flying]
isFlying = false
char.Animate.Disabled = false
idleAnim:Stop()
flyingAnim:Stop()
elseif not isFlying then --[if they are not flying]
isFlying = true
char.Animate.Disabled = true
idleAnim:Play()
local bv = Instance.new('BodyVelocity')
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Name = 'FlightForce'
bv.Velocity = Vector3.new(0,0,0)
bv.Parent = char.HumanoidRootPart
repeat wait(.1) until isFlying == false --[wait until not isFlying to destroy bv]
bv:Destroy()
end
end
---[Setting movement keys to true]---
if key.KeyCode == Enum.KeyCode.W then
wPressed = true
elseif key.KeyCode == Enum.KeyCode.S then
sPressed = true
elseif key.KeyCode == Enum.KeyCode.A then
aPressed = true
elseif key.KeyCode == Enum.KeyCode.D then
dPressed = true
end
end)
UIS.InputEnded:connect(function(key,blah) --[The character is still flying bc isFlying is still true]
if blah then return end
if key.KeyCode == Enum.KeyCode.W then
wPressed = false
--print('no longer pressing w')
elseif key.KeyCode == Enum.KeyCode.S then
sPressed = false
--print('no longer pressing s')
elseif key.KeyCode == Enum.KeyCode.A then
aPressed = false
--print('no longer pressing a')
elseif key.KeyCode == Enum.KeyCode.D then
dPressed = false
--print('no longer pressing d')
end
end)
game:GetService("RunService").RenderStepped:Connect(function() --[runs every frame for a smoother version rather than wait()]
if isFlying then
char.HumanoidRootPart:FindFirstChild('FlightForce').Velocity = Vector3.new(0,0,0) --[Since w,a,s,d is not true yet, we don't move]
flyingAnim:Stop()
--[Direction the character is facing and stuff]--
--[This is where I tried a few solutions, but it's not what I wanted]--
local MousePos= mouse.Hit.p
local lookVector = Vector3.new(MousePos.X,MousePos.Y,MousePos.Z)
--char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.CFrame.p,camera.CFrame.LookVector)
--[[local bg = Instance.new("BodyGyro") -- Body Gyro that determines your rotation
bg.MaxTorque = Vector3.new(400000,400000,400000)
bg.D = 10
bg.CFrame = CFrame.new(char.HumanoidRootPart.CFrame.p,lookVector)
bg.Parent = char.HumanoidRootPart]]
---[The main movement stuff]---
if wPressed then
char.HumanoidRootPart:FindFirstChild('FlightForce').Velocity = camera.CFrame.LookVector * 50
flyingAnim:Play()
elseif aPressed then
char.HumanoidRootPart:FindFirstChild('FlightForce').Velocity = camera.CFrame.RightVector * -50
flyingAnim:Play()
elseif sPressed then
char.HumanoidRootPart:FindFirstChild('FlightForce').Velocity = camera.CFrame.LookVector * -50
flyingAnim:Play()
elseif dPressed then
char.HumanoidRootPart:FindFirstChild('FlightForce').Velocity = camera.CFrame.RightVector * 50
flyingAnim:Play()
end
end
end)