Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

4 comments

0

Goulstem am I allowed to overcomplicate things and use BodyGyro.CFrame = CFrame.new(pos,point) instead?

0

I'm not sure a BodyGyro would have the same effect but feel free to test.

0

It does work with BodyGyro, in fact that's exactly how you use BodyGyro.

2

Well sweet

This discussion is preserved as it was. New answers, comments, and votes are closed.