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

I'm having problems rotating my character based off Joystick, can someone help?

Asked by 3 years ago
Edited 3 years ago

I'm trying to rotate the player in the direction the Joystick is facing, it works however it's off 90°, meaning if you hold UP(?) the character looks LEFT. If you hold RIGHT(?) the character looks UP. If you hold DOWN(?) the character looks RIGHT. And if you look LEFT(?) the character looks DOWN. I am using a Top-Down camera, not sure if that matters but that is why I said "Looks up,right,down,left" I think my problem is in this code here

local rootPart = player.Character:FindFirstChild("HumanoidRootPart")

rootPart.CFrame = CFrame.new(
            rootPart.Position,
            rootPart.Position + Vector3.new(inputObject.Position.x - centerPosition.x, 0, inputObject.Position.y - centerPosition.y)
        )

If you need more information just comment here and I won't mind. I believe I need to add an offset of some sort but I'm not quite sure. Any help is appreciated and I look forward to your replies. Thanks!

0
Perhaps this could be fixed just by adding a rotation of 90?: ... * CFrame.Angles(0, math.rad(90), 0). Not 100% sure if this will fix your issue. Tkdriverx 514 — 3y
0
Thank you @Tkdriverx, I needed (-90) but you led me in the right direction. It works perfectly now. 8Bit_Taz 40 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
local rootPart = player.Character:FindFirstChild("HumanoidRootPart")

rootPart.CFrame = CFrame.new(
            rootPart.Position,
            rootPart.Position + Vector3.new(inputObject.Position.x - centerPosition.x, 0, inputObject.Position.y - centerPosition.y)
        ) * CFrame.Angles(0, math.rad(-90), 0)
Ad

Answer this question