Hello, I am attempting to make a script that makes the player’s character move to the camera line of view. I’ve been looking everywhere and I cannot find a single solved topic about that. There is an example video that might help understanding (look from 0:14 to to 0:19).
1 Like
local Game = game
local Workspace = workspace
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = Workspace.CurrentCamera
local function OnRenderStep()
Character:PivotTo(CFrame.new(Character:GetPivot().Position) * CFrame.Angles(Camera.CFrame:toOrientation()) * CFrame.Angles(math.pi / -2, 0, 0))
end
RunService.RenderStepped:Connect(OnRenderStep)
1 Like
The script is very glitched, but thanks for sharing it.
It’s ‘glitchy’ because you need to modify it so that it’s only enabled while a player is suspended in the air, not while a player is grounded. As I’m not privy to the flight system you’re using I left that implementation detail to you.
Place this inside of a while loop, but first make these variables outside of any functions:
local wPressed = false
local aPressed = false
local sPressed = false
local dPressed = false
If your script uses velocity then this should be helpful:
Also you need to make sure you have validations in your script whenever you’re idle in the air, as to what Forummer said. His/Her’s function works, but this is just my personal take on this.
if isFlying then
local bv = root:FindFirstChild("FlightVelocity")
root:FindFirstChild("FlightVelocity").Velocity = Vector3.new(0,0,0)
if wPressed then
root:FindFirstChild("FlightVelocity").Velocity = cam.CFrame.LookVector * 22
elseif aPressed then
root:FindFirstChild("FlightVelocity").Velocity = cam.CFrame.RightVector * -22
elseif sPressed then
root:FindFirstChild("FlightVelocity").Velocity = cam.CFrame.LookVector * -22
elseif dPressed then
root:FindFirstChild("FlightVelocity").Velocity = cam.CFrame.RightVector * 22
else
root:FindFirstChild("FlightVelocity").Velocity = Vector3.new(0,0,0)
end
end