Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i rotate player to look the model?

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

✓ Accepted answer

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.

5 comments

0

This is worked! thanks for your answer!!

0

But i have a question, why when this code started, i'll jump?

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.

0

I do use R15, and i press E(the keycode), i'll jump. Maybe is height difference?

0

I found it! i can use LowerTorso to take this problem! anyways. thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.