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

How to use body forces and body gyro correctly?

Asked by 8 years ago

Hey guys I've been playing around with body forces and body gyros for a few hours not to no success. I want a brick to go to where i click gradually and stop as soon as it reaches where i click.

Currently i have a system which causes the brick to move to where i want but wont stop till after the point as it needs to slow down and its also currently rotating like crazy, i want it to face the direction it is traveling.

Below is my code.

01local UIS = game:GetService("UserInputService")
02local plr = game.Players.LocalPlayer
03local mouse = plr:GetMouse()
04 
05local speed = 20
06local selectedUnit = nil
07 
08UIS.InputBegan:connect(function(input)
09    if input.UserInputType == Enum.UserInputType.MouseButton1 then
10        if mouse.Target then
11            if mouse.Target.Name == "Unit" then
12                selectedUnit = mouse.Target
13            elseif mouse.Hit then 
14                if selectedUnit then 
15                    print("move unit")
View all 28 lines...

Any suggestions, improvements, tips or even a complete re-haul of what i'm attempting would be appreciated.

0
i wouldnt know how to do it myself but assuming you know how to do it just do this; create an invisible part at the point where the player clicked, then set the BodyPosition of the part you are trying to move to the placed parts position, and delete the part ace12345678135 50 — 8y
0
Thanks for the input but this is not quite what i need. jordan0810 55 — 8y

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
8 years ago
Edited 8 years ago

You should use a BodyPosition, as that's pretty much exactly what it's for. And might not need a BodyGyro. Here's my attempt.

01local player = game.Players.LocalPlayer
02local UIS = game:GetService('UserInputService')
03local mouse = player:GetMouse()
04 
05UIS.InputBegan:connect(function(input,gpe)
06    if gpe then return end
07    if input.UserInputType == Enum.UserInputType.MouseButton1 then
08        --mouse click
09        local char = player.Character
10        if char and mouse.Target then
11            local head = char.PrimaryPart
12            if head then
13                local p = mouse.Hit.p  
14 
15                local part = Instance.new('Part')
View all 33 lines...
Ad

Answer this question