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

How could I anchor a part's rotation but not it's position?

Asked by 5 years ago

I'm making an iron man inspired flight suit with an old buddy of mine, but I've been tasked with the flight script, and I can't get the character to point in the direction of the mouse. * The script works, but looks dull in-game without the character pointing in the direction. Here's the script (it's a server script):

b = Instance.new("BodyPosition")
b.Parent = torso
b.Position = torso.Position+(tuple[2]-torso.Position).unit * power
b.MaxForce = Vector3.new(50000000, 50000000, 50000000)
game:GetService("Debris"):AddItem(b, 0.1)

local ray = Ray.new(torso.Position, (tuple[2] - torso.Position).unit * power)
local a, position = workspace:FindPartOnRay(ray, character, false, true)

local beam = Instance.new("Part", workspace)
beam.FormFactor = "Custom"
beam.Transparency = 0
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false

local distance = (torso.Position - position).magnitude
beam.Size = Vector3.new(0.3, 0.3, distance)
beam.CFrame = CFrame.new(torso.Position, position) * CFrame.new(0, 0, -distance / 2)
beam.Position = torso.Position

weld = Instance.new("Weld", beam)
weld.C1 = CFrame.Angles(math.rad(-90), 0, 0)
weld.Part0 = torso
weld.Part1 = beam

game:GetService("Debris"):AddItem(beam, 0.09)

tuple[2] is the mouse.Hit.p at the current time. This script is mostly copied off robloxdev.com/. Also, is there any way to not have to put the a in "a, position"? I tried but that's the only way to make it work for me. Thanks for your time. :)

1 answer

Log in to vote
0
Answered by 5 years ago

Well if you'd want the player to point to the direction of mouse you'd have to use the CFrame property of BodyGyro. You would then in brackets have to tell which direction the player should face:

local BG = Instance.new("BodyGyro")
BG.Parent = Player.Character.HumanoidRootPart
BG.CFrame = CFrame.new(root.Position,tuple[2])--If its Mouse.hit.p like u said it is leave it like this but if not add a ".p" to tuple[2].

This will basically look at the first position root.Position then make the root look at the mouse(the second position). Here's the wiki better describe bodygyro.

0
This has worked but it pointing the player face on at the mouse, is it possible to make the player rotate to they're facing down but the head is pointing at the mouse? User#25069 0 — 5y
0
nvm i worked it out thanks :) User#25069 0 — 5y
Ad

Answer this question