in a game i am coding when someone opens a door a little animation will play of them touching the keypad for the animation to like nice i need to teleport the character to the right distance away then face the character towards the keypad i can teleport the character but i am stumped on trying to face the character on a angle when right now if someone clicked the keypad on a angle the animation would play but it would be completely off i tried multiple tutorials but they don't work any help?
A quick and dirty way of moving a player's character (without changing their rotation) is using the "Model:MoveTo()" function (and a Vector3 in the curly braces to set a position).
But since you are seeking help to turn I would recommend the more complicated method of using the "Model:SetPrimaryPartCFrame()" function in order to both move and rotate the player.
Assuming the player clicks on a keypad in the "physical world" by clicking on parts via a ClickDetector you can get the player's model via this method:
game.Workspace.Part.ClickDetector.MouseClick:Connect(function(Player) local CharacterModel = Player.Character --Gets the player's character model CharacterModel:SetPrimaryPartCFrame(CFrame.new(x, y, z) * CFrame.Angles(math.rad(degreesX), math.rad(degreesY), math.rad(degreesZ))) --[[ You can also do the following which is what the function does as well: CharacterModel.PrimaryPart.CFrame = CFrame.new(yadda yadda code stuff...) * CFrame.angles(yadda yadda more code stuff...) ]]-- end) --The ClickDetector always returns the player who clicked on it
Details about the "Model:SetPrimaryPartCFrame()" here: https://developer.roblox.com/en-us/api-reference/function/Model/SetPrimaryPartCFrame
If you want to get the model's CFrame for other purposes then lookie here: https://developer.roblox.com/en-us/api-reference/function/Model/GetPrimaryPartCFrame
If you have any questions or issues contact me. ;)
https://developer.roblox.com/en-us/api-reference/datatype/CFrame
Change the CFrame of the user's HumanoidRootPart to a position p that looks at position a like so character.HumanoidRootPart.CFrame = CFrame.new(p, a)
You would have to find p
. I would suggest using the keypads location and adding an offset of a few studs. a
would just the the position of the keypad