Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make the character point to a certain direction with userinputservice?

Asked by 6 years ago

I'm making a 2d game where when you press "s" the player points towards the camera without moving.

0
BodyGyro is probably what you're looking for: http://wiki.roblox.com/index.php?title=BodyMover#BodyGyro mattscy 3725 — 6y
0
im not very good with body gyro, is there an easier way to rotate the character Gavinboy3000 98 — 6y

1 answer

Log in to vote
0
Answered by
ax_gold 360 Moderation Voter
6 years ago
Edited 6 years ago

Well, it's actually quite simple, and you don't need BodyGyro at all. Just change the CFrame of the Character's HumanoidRootPart to the same position, and change the angle to The Camera's CFrame position. Here's an example with what you want to do.

Note: I changed the button you press from S to F so I could make sure it worked. S makes you walk backwards if your game isn't 2D :P. If you want to change it back, change Enum.KeyCode.F at line 5 to Enum.KeyCode.S.

local player = game:GetService("Players").LocalPlayer
local usi = game:GetService("UserInputService")

usi.InputBegan:connect(function(obj)
    if obj.KeyCode == Enum.KeyCode.F then
        local character = workspace:FindFirstChild(player.Name)
        local camera = workspace.CurrentCamera
        character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.CFrame.p, camera.CFrame.p * -1)
    end
end)
0
thanks Gavinboy3000 98 — 6y
Ad

Answer this question