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

How would one get a brick to point to another moving one?

Asked by 8 years ago

My objective is to make a tracking part that swivels, following the movements of a projectile. This is my current failure of a script:

Stop = false

game.Workspace.ProjectilePhysicsTest.Projectile.Touched:connect(function (touched)
    if touched.Name == "Baseplate" then
        Stop = true
    end
end)

repeat
    wait()
    script.Parent.Rotation = (script.Parent.Position - game.Workspace.ProjectilePhysicsTest.Projectile.Position).magnitude * game.Workspace.ProjectilePhysicsTest.Projectile.Position
until Stop == true

Any help would be appreciated.

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

There is a CFrame constructor that does precisely what you want. The syntax for it is this;

CFrame.new( Vector3 origin, Vector3 look)

origin being the position of the part, and look being where the part is looking at.

Stop = false

game.Workspace.ProjectilePhysicsTest.Projectile.Touched:connect(function(touched)
    if touched.Name == "Baseplate" then
        Stop = true
    end
end)

repeat
    wait()
    script.Parent.CFrame = CFrame.new(
        script.Parent.CFrame.p,
        workspace.ProjectilePhysicsTest.Projectile.CFrame.p
    )
until
    Stop

Note: This CFrame constructor always points the FrontSurface or the part to the look argument

0
Goulstem am I allowed to overcomplicate things and use BodyGyro.CFrame = CFrame.new(pos,point) instead? DragonODeath 50 — 8y
0
I'm not sure a BodyGyro would have the same effect but feel free to test. Goulstem 8144 — 8y
0
It does work with BodyGyro, in fact that's exactly how you use BodyGyro. funyun 958 — 8y
2
Well sweet Goulstem 8144 — 8y
Ad

Answer this question