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

Rotating a part to face mouse, With body gyro?

Asked by
lucas4114 607 Moderation Voter
8 years ago

I'm trying to make a part's rotation face the player's mouse when the player holds down "w", and only on the Y rotation. It doesn't work, the output prints w is down, and the loop worked over and over again untill I stop pressing "w" , so those 2 work, but the part still doesn't rotation on Y to face the part!1 And it isn't because the "script.Parent.GetMousePosition.MousePosition.Value" isn't working, I put a print in that script too, and it DOES work.. Hellllp mee?

local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Car = game.Workspace:FindFirstChild(""..Plr.Name.."'s_Car")
local Speed = 5000000
local WIsDown = script.Parent.WScript.WIsDown


WIsDown.Changed:connect(function(Value)
    if Value == true then
        print("w is down")
        local Force = Instance.new("BodyGyro")
        Force.maxTorque = Vector3.new(0,Speed,0)
        Force.D = 10000
        Force.P = 10000
        Force.Name = "TurnForce"
        repeat
            print("the loop worked")
            wait(0.05)
            Force.cframe = script.Parent.GetMousePosition.MousePosition.Value
        until WIsDown.Value == false
        Force:Destroy()
    end
end)

1 answer

Log in to vote
0
Answered by 8 years ago

You don't need body gyro. You can use a special feature with CFrame that allows you to input 2 vectors as 1st and second arguments, and returns a nice CFrame that points to it's second argument.

Like this:

p.CFrame = CFrame.new(OriginalPosition, PointToPosition)

So, here could be your script:

local Plr = game.Players.LocalPlayer
local Mouse = Plr:GetMouse()
local Car = game.Workspace:FindFirstChild(""..Plr.Name.."'s_Car")
local Speed = 5000000
local WIsDown = script.Parent.WScript.WIsDown

local Part = nil -- assuming a part's value is here


WIsDown.Changed:connect(function(Value)
    if Value == true then
        print("w is down")
        repeat
            wait(0.05)
            Part.CFrame = CFrame.new(Part.Position, Mouse.Hit.p)
        until WIsDown.Value == false
    end
end)

If you want more help on how to use this stuff, PM me.

0
I'm usinf body gyro because this part is in a model, I need body gyro for what I'm making. lucas4114 607 — 8y
0
Using* lucas4114 607 — 8y
0
Omg I know what I did wrong now, I didn't give the force a parent lol, ty I would of not realized that without reading your code xd lucas4114 607 — 8y
0
Yw, lol. CodingEvolution 490 — 8y
Ad

Answer this question