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

Move a part to where you click

I have been trying hard to make a script that makes it so when you click a location, a block will turn and move to the desired location using BodyGyro's for the turning and BodyPositions for the moving.

I need some sort of more basic script that can help me out with this issue. The original script did not have proper turning, and if clicking was between 1 and 25 studs away, it only moves like 2 studs. My scripting with BodyObjects is not that good, and the wiki is not much help with this situation.

Requested section of script. Issues:

-Moving is bugged [Fixed, Part for Camera was messing with positioning]

-Turning is bugged

script.Parent.Enabled = false
	script.Updater.Disabled = true
	script.Target.Value = nil
	local Ship = script.OwnedShip.Value
	local MouseHit = nil
	if Ship ~= nil then
		MouseHit = Mouse.hit
		local Part = Instance.new("Part")
		Part.FormFactor = "Symmetric"
		Part.Transparency = 0
		Part.Size = Vector3.new(4,4,4)
		Part.Anchored = true
		Part.CanCollide = false
		Part.CFrame = CFrame.new	(MouseHit.X,game.Workspace.Map0.MapBase.Position.Y,MouseHit.Z)
		Part.Parent = game.Workspace
		
		Ship.Functional.Main.Move.position = Vector3.new	(MouseHit.X,game.Workspace.Map0.MapBase.Position.Y + 5,MouseHit.Z)
		--Ship.Functional.Main.Gyro.cframe = CFrame.new(Vector3.new(0,0,0),Part.Position)
		
		local vec = Part.Position - Ship.Functional.Main.Position --Section from Grapple Gun
		local lenSquared = vec.magnitude * vec.magnitude
		local invSqrt = 1 / math.sqrt(lenSquared)
		Ship.Functional.Main.Gyro.cframe = CFrame.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)

2 comments

0

Please post the script you're having trouble with. We won't just write a new one for you.

0

Ok, it is there, ask any needed questions, I want this fixed soon. :P

1 answer

✓ Accepted answer

You should be able to set this as your Gyro's cframe to get it to point towards the mouse.

 Ship.Functional.Main.Gyro.cframe = CFrame.new(Ship.Functional.Main.CFrame.p, Mouse.Hit.p)

2 comments

0

Ok, thanks, ill test it in the morning. I will work on the moving myself, that was my only big issues.

0

Ok, that works. I will work on the moving... I have an idea to change it to make it better...

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