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

BodyGyro not looking at Target?

Asked by 5 years ago
Edited 5 years ago

The BodyPosition is working fine but the BodyGyro is not looking at TARGET no matter what I do.

local RocketCopy = module.LaserShoot(EquippedRocket) -- Module with Custom Parts
local Rocket = RocketCopy:Clone() 
Rocket.CFrame = CFrame.new(player.Character.Torso.CFrame.p) 
Rocket.Parent = workspace
debris:AddItem(Rocket, 2)

local BodyPosition = Instance.new("BodyPosition", Rocket)
BodyPosition.MaxForce = Vector3.new(50,65,50)
BodyPosition.D = 1800
BodyPosition.P = 48000

local bodyGyro = Instance.new("BodyGyro",Rocket)
bodyGyro.MaxTorque = Vector3.new(80000,80000,80000)
bodyGyro.P = 25000
bodyGyro.D = 700
BodyPosition.Position = workspace.TARGET.Position

local function TargetLook()
    while Rocket.Parent ~=nil do
    wait(.1)
        bodyGyro.CFrame = CFrame.new(Rocket.Position,workspace.TARGET.CFrame.LookVector *100)
    end
end

spawn(function()TargetLook() end)

2 answers

Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago

Unlike Ray.new's 2nd parameter as a direction relative to the origin, CFrame.new(pos, lookAt) constructor's 2nd parameter is a vector in world space.

You'll need to do:

lua BodyGyro.CFrame = CFrame.new(Rocket.Position, Rocket.Position + workspace.TARGET.CFrame.lookVector * 100)

0
still not working, the rocket keep looking at one direction all time iagometroid 61 — 5y
0
instead of TARGET I change to Character.Torso and works fine, i dont understand why TARGET dont work... iagometroid 61 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

What you can do to make the BodyGyro face the target is set the CFrame of BodyGyro to the Rocket and Target's position.

Something like this:

BodyGyro.CFrame = CFrame.new(Rocket.Position, workspace.TARGET.Position)

Answer this question