How to control a part with wasd and arrowkeys

Got the final problem i have been changing camera CFrame but i need to change only it’s position i guess this would help you i guess.

			local cam = game.Workspace.Camera
			mouse.Move:Connect(function()
				if mouse.Hit.p ~= prev_mousehit  then
					vrhead.CFrame = CFrame.new(vrhead.Position,Vector3.new(cam.CFrame.LookVector.X,cam.CFrame.LookVector.Y,cam.CFrame.LookVector.Z) + vrhead.Position )
					prev_mousehit = mouse.Hit.p
				end
			end)
			local boolt = false
			uis.InputBegan:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.W then
					boolt = true
					while boolt do
						wait(0.02)
						vrhead.Position += Vector3.new(cam.CFrame.LookVector.X * 1,0,cam.CFrame.LookVector.Z * 1)
					end
				end
			end)
			uis.InputEnded:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.W then
					boolt = false
				end
			end)

now how do I make it so it will go down when Im looking down while pressing w

vrhead.Position += Vector3.new(cam.CFrame.LookVector.X * 1,0,cam.CFrame.LookVector.Z * 1)

see this line? if yes then change it to this

vrhead.Position += Vector3.new(cam.CFrame.LookVector.X,cam.CFrame.LookVector.Y,cam.CFrame.LookVector.Z )

IT WORKS! tysm!! thank you for helping me. No other things would help!

It is my problem that i didn’t see that i change CFrame instead of position

how could I do this with a and d isntead of just w and s
@kercig

In fact you can just add an attachment and place it in 1 studs to the part’s right side and add to it’s position the vector difference between their positions
Something like that

local attachment
local diff = attachment.WorldPosition - vrhead.Position

And then increase it’s position with this difference

vrhead.Position += diff

Or just set vrhead position to world position of an attachment

i have this what would I do:

	uis.InputBegan:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.A then
					boolq = true
					while boolq do
						wait(0.02)
						vrhead.Position += Vector3.new(cam.CFrame.LookVector.X,0,0)
					end
				end
			end)
			uis.InputEnded:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.A then
					boolq = false
				end
			end)
			uis.InputBegan:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.D then
					boole = true
					while boole do
						wait(0.02)
						vrhead.Position += Vector3.new(-cam.CFrame.LookVector.X,0,0)
					end
				end
			end)
			uis.InputEnded:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.D then
					boole = false
				end
			end)

Put an attachment in vrhead and move it to the right

	local attachment = Instance.new("Attachment",vrhead)
	attachment.Position = Vector3.new(0,0,1) -- try this or this attachment.Position = Vector3.new(1,0,0)

	
	uis.InputBegan:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.A then
					boolq = true
					while boolq do
						wait(0.02)
						local diff  = attachment.WordPosition - vrhead.Position
						vrhead.Position -= diff
					end
				end
			end)
			uis.InputEnded:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.A then
					boolq = false
				end
			end)
			uis.InputBegan:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.D then
					boole = true
					while boole do
						wait(0.02)
						local diff  = attachment.WordPosition - vrhead.Position
						vrhead.Position += diff
					end
				end
			end)
			uis.InputEnded:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.D then
					boole = false
				end
			end)

Hello everyone.

This script is great, but I’m wondering, how could you make it so it moves to the right and the left?

Thanks.

vrhead is created via script so idont know how to position it

so you can just make this

local attachment = Instance.new("Attachment",vrhead)
attachment.Position = Vector3.new(0,0,1) -- try this or this attachment.Position = Vector3.new(1,0,0)

So the final version will be something like this

	local attachment = Instance.new("Attachment",vrhead)
	attachment.Position = Vector3.new(0,0,1) -- try this or this attachment.Position = Vector3.new(1,0,0)

	
	uis.InputBegan:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.A then
					boolq = true
					while boolq do
						wait(0.02)
						local diff  = attachment.WordPosition - vrhead.Position
						vrhead.Position -= diff
					end
				end
			end)
			uis.InputEnded:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.A then
					boolq = false
				end
			end)
			uis.InputBegan:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.D then
					boole = true
					while boole do
						wait(0.02)
						local diff  = attachment.WordPosition - vrhead.Position
						vrhead.Position += diff
					end
				end
			end)
			uis.InputEnded:Connect(function(key)
				if key.KeyCode == Enum.KeyCode.D then
					boole = false
				end
			end)

it like blasts of up and down really fast

Can you send a video pls?

wait i think i fixed it not sure

yep it worked thank you so much

No problems :slight_smile:

you’re probably not going to read this message…
BUT THANK YOU SO MUCH!!!

1 Like