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

How do i rotate player to look the model?

Asked by 6 years ago

I wanna make a hacking computer games.And i want the player look at computer. These is my coding, and thanks for helping!

local player = game.Players.LocalPlayer
local character = player.Character.Humanoid
local Computer  = game.Workspace.Computer.Keyboard.Body
local radius = 10

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.E then
        if player:DistanceFromCharacter(Computer.Position) <= radius then
            character:MoveTo(workspace.Computer.Hack.Position)
            --Rotate myself please C:
        end
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

When you're rotating a player to make them face something, use CFrame. This particular method can be found in the second entry on this page under Quick Reference.

character.Parent.Head.CFrame = CFrame.new(character.Parent.Head.Position,Computer.Position)
-- character.Parent is used because you define character as their humanoid.
0
This is worked! thanks for your answer!! MEndermanM 73 — 6y
0
But i have a question, why when this code started, i'll jump? MEndermanM 73 — 6y
0
It's just related to physics and CFrame and whatnot. If your game uses R6 and not R15, you could use the character's Torso instead for this which seems to be a little smoother. TheBenSquare 47 — 6y
0
I do use R15, and i press E(the keycode), i'll jump. Maybe is height difference? MEndermanM 73 — 6y
0
I found it! i can use LowerTorso to take this problem! anyways. thank you! MEndermanM 73 — 6y
Ad

Answer this question