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

Move a part to where you click

Asked by 10 years ago

I have been trying hard to make a script that makes it so when you click a location, a block will turn and move to the desired location using BodyGyro's for the turning and BodyPositions for the moving.

I need some sort of more basic script that can help me out with this issue. The original script did not have proper turning, and if clicking was between 1 and 25 studs away, it only moves like 2 studs. My scripting with BodyObjects is not that good, and the wiki is not much help with this situation.

Requested section of script. Issues:

-Moving is bugged [Fixed, Part for Camera was messing with positioning]

-Turning is bugged

script.Parent.Enabled = false
    script.Updater.Disabled = true
    script.Target.Value = nil
    local Ship = script.OwnedShip.Value
    local MouseHit = nil
    if Ship ~= nil then
        MouseHit = Mouse.hit
        local Part = Instance.new("Part")
        Part.FormFactor = "Symmetric"
        Part.Transparency = 0
        Part.Size = Vector3.new(4,4,4)
        Part.Anchored = true
        Part.CanCollide = false
        Part.CFrame = CFrame.new    (MouseHit.X,game.Workspace.Map0.MapBase.Position.Y,MouseHit.Z)
        Part.Parent = game.Workspace

        Ship.Functional.Main.Move.position = Vector3.new    (MouseHit.X,game.Workspace.Map0.MapBase.Position.Y + 5,MouseHit.Z)
        --Ship.Functional.Main.Gyro.cframe = CFrame.new(Vector3.new(0,0,0),Part.Position)

        local vec = Part.Position - Ship.Functional.Main.Position --Section from Grapple Gun
        local lenSquared = vec.magnitude * vec.magnitude
        local invSqrt = 1 / math.sqrt(lenSquared)
        Ship.Functional.Main.Gyro.cframe = CFrame.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
0
Please post the script you're having trouble with. We won't just write a new one for you. adark 5487 — 10y
0
Ok, it is there, ask any needed questions, I want this fixed soon. :P FromLegoUniverse 264 — 10y

1 answer

Log in to vote
1
Answered by
MrNicNac 855 Moderation Voter
10 years ago

You should be able to set this as your Gyro's cframe to get it to point towards the mouse.

 Ship.Functional.Main.Gyro.cframe = CFrame.new(Ship.Functional.Main.CFrame.p, Mouse.Hit.p)
0
Ok, thanks, ill test it in the morning. I will work on the moving myself, that was my only big issues. FromLegoUniverse 264 — 10y
0
Ok, that works. I will work on the moving... I have an idea to change it to make it better... FromLegoUniverse 264 — 10y
Ad

Answer this question